I aim to avoid AsyncTask's onPostExecute() being called. cancel() can't help me, because it doesnt work in 100% cases: sometimes cancel() returns false and later onPostExecute() of the task is called. How to prevent this? I created boolean flag in my class and set it to true instead of invoking cancel(), but it is hardly a good solution:
public class GetIcons extends AsyncTask<Void, Void, HashMap<String, Bitmap>>
{
public boolean skipPostExecute = false;
@Override
protected HashMap<String, Bitmap> doInBackground(Void... arg0)
{
// do something (getting icons from webserver)
}
@Override
protected void onPostExecute(HashMap<String, Bitmap> result)
{
super.onPostExecute(result);
if (!skipPostExecute)
{
// do something
}
}
}
Is there a better way to do the same?