Friday, 13 September 2013

Handler not behaving like a thread

Handler not behaving like a thread

Well so here is my Runnable code
// TODO Auto-generated method stub
Log.i(MyTag.Tag, "Started connecting");
String RawData = connect(link);//This method connects to the internet
Log.i(MyTag.Tag, "Finished connecting");
MyParser parse = new MyParser();
Document doc = null;
try {
Log.i(MyTag.Tag, "Starting parsing..");
doc = parse.parseAndReturn(RawData);
Log.i(MyTag.Tag, "Finished parsing");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DAF.finishLoading(doc);
The problem is, with a normal Thread, the app will stay for a few seconds at
connect(link)
,while it downloads the webpage before moving on to the rest of the code.
But with a handler, it just skips everything and goes all the way to
DAF.finishLoading(doc)
Which is not what I want.
I need a handler to allow the app to perform this method on a fixed
interval, but how do I make my handler behave like how I want with a
normal thread?
I know one method is to not use normal Runnables to perform internet
connectivity, but rather to use AsyncTask. But that is quite a hassle to
re-write everything so I was wondering if there is anyway to solve this
problem.

No comments:

Post a Comment