Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Calling the methods on UI thread from AsyncTask doInBackground method

I am using AsyncTask to upload data to UI. i wrote the code to download data from server in a separate method and i am calling that method from doinBackground. It will give error because UI methods can't access from doInBackground.but, i want to access . any alternative process is there to access the UI method from doinBackground.?

like image 414
balu... Avatar asked Mar 15 '12 11:03

balu...


1 Answers

any alternative process is there to access the UI method from doinBackground.?

Call publishProgress() in doInBackground(). Put your UI-updating logic in onProgressUpdate() of your AsyncTask. onProgressUpdate() will be called on the main application thread (a.k.a., UI thread) after you call publishProgress(). Here is a sample project demonstrating this.

like image 189
CommonsWare Avatar answered Oct 13 '22 01:10

CommonsWare