For some reason my onPostExecute()
is not called after my AsyncTask
finishes.
My class decleration:
public class setWallpaper
Made another nasty mistake that can result in this same error. When defining the AsyncTask and calling it, I was not calling execute
but was calling doInBackground
new AsyncTask<String,Void,Void>() {
....
}.doInBackground("parameter");
rather than
new AsyncTask<String,Void,Void>() {
....
}.execute("parameter");
I have faced the same problem. None of the above solutions worked for me. Then i figured out the problem maybe it helps someone else .
In UI thread i call the following codes:
public class XActivity ...{
onCreate(){
....
new SaveDrawingAsync(this).execute();
while(true)
{
if(MandalaActivity.saveOperationInProgress){
continue;
}
super.onBackPressed();
break;
}
...
}
}
My AsyncTask class definition :
public class SaveAsync extends AsyncTask<Object, Void, Void> {
@Override
public Void doInBackground(Object... params) {
saveThem(); // long running operation
return null;
}
@Override
public void onPostExecute(Void param) {
XActivity.saveOperationInProgress = false;
}
@Override
public void onPreExecute() {
XActivity.saveOperationInProgress = true;
}
}
in the above code onPostExecute is not called. It is because of an infinite loop after asynctask execution . asynctask and inifinite loop both waits eachother to finish. Thus the code stucks!
The solution is changing the design!