I have been searching for the answer but no one really answers because there is no point using async task for that. In Android API 11 or above it will force to code it you do network requests on the main thread so I have to do async task. So, here is the question: Is it possible to wait untill the async task is finished then continue? Because I need the data to be there for the calling method etc.
Here is my code:
public JSONObject getJSONFromUrl(String url) {
this.url = url;
new loadURL().execute();
// Do this when ASYNC HAS FINISHED
return jObj;
}
class loadURL extends AsyncTask <Void, Void, Void> {
protected void onPreExecute() {
}
protected Void doInBackground(Void... unused) {
//do stuff in background
return (null);
}
}
}
Any questions to answer just leave a comment. Thanks for helping.
yes you use the onPostExecute
method of the AsyncTask
to do whatever you want to do after. That method gets called after the doInBackground
is finished
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With