asynchronous - Android AsyncTask still hanging UI -
i'm using asynctask grab data web, still seems hanging ui while fetching data.
my code: https://gist.github.com/masterejay/10005933
the threadparse class inside main class, , initwebview method inside of main class, not threadparse.
you should launch asynctask using execute
method.
with code call method in main thread. execute
create new thread asynctask.
public void initwebview(string link) { threadparse parse = new threadparse(); parse.execute(link); }
if really need ui in doinbackground
should use runonuithread
i taked code block example
catch (indexoutofboundsexception ex){ currentpage = 1; totalpages = 1; toast.maketext(thread.this, "you on " + currentpage + " of " + totalpages, toast.length_long).show(); webview.loaddatawithbaseurl("http://netdna.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css", e.html(), "text/html", "utf-8", null); return; }
here, let work should do
catch (indexoutofboundsexception ex){ yourtopactivity.this.runonuithread(new runnable() { currentpage=1; totalpages=1; toast.maketext(thread.this,"you on "+currentpage+" of "+totalpages,toast.length_long). show(); webview.loaddatawithbaseurl("http://netdna.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css",e.html(),"text/html","utf-8",null); }); return; }
same other things works ui elements.
runonuithread
documentation.
here yourtopactivity
needed because should use runonuithread
method of activity
, inside asynctask
class.
anyway, should rethink code use onpostexecute
, onpreexecute
Comments
Post a Comment