Saturday, 31 August 2013

View not attached to window manager exception even isfinishing is called

View not attached to window manager exception even isfinishing is called

I keep getting this exception "View not attached to window manager"
reports from ACRA and it is always happening around my dialog.dismiss() in
my async task. I have searched SO and I added the (!isFinishing())
condition but I still get it. Can you please tell me how I can solve it?
Here is a sample code where it happens
private class MyAsyncTask extends AsyncTask<String, Void, Void> {
private ProgressDialog dialog;
private PropertyTask asyncTask;
public MyAsyncTask (PropertyTask task){
this.asyncTask = task;
}
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(ListTasksActivity.this, "Please
wait..", "working..", true);
}
@Override
protected Void doInBackground(String... params) {
//Some DB work here
return null;
}
@Override
protected void onPostExecute(Void result) {
if(!isFinishing()){
dialog.dismiss(); <-------- Problem happens
}
}
}

No comments:

Post a Comment