Reputation: 1191
I want to know when the asynctask is finished, such that I could update the UI.
Can anybody help???? thanks!!!
public String[] getinfo(int id) {
String[] QueueNo = null;
try {
new DLfromServer().execute("url link"); // this is the asynctask
// want to do stuff here after the asynctask is completed
// actually I want to return a string result after the task is finished....
}
} catch (JSONException e) {
Log.e("GetJSON", "Err:", e);
}
return QueueNo;
}
Upvotes: 0
Views: 569
Reputation: 132992
want to know when the asynctask is finished, such that I could update the UI.
Yes, you can use onPostExecute
method which call on UI Thread after doInBackground
execution is completed.
if you want to get data back on Main UI Thread then use AsyncTask.get() method for executing AsyncTask because this method make wait on UI Thread until doInBackground
execution is completed .
String str_result= new DLfromServer().execute("url link").get();
// now use str_result for Updating result
NOTE :- you will need to call AsyncTask.get()
inside an Thread instead of Main UI Thread otherwise calling of get() method will freeze Main Thread until doInBackground
execution is complete
Upvotes: 1