My app frequently throws android.view.WindowLeaked exception --
<p>My app frequently throws exception like below:</p>

<blockquote>
  <p>E/WindowManager( 6282): android.view.WindowLeaked: Activity
  com.myActivity has leaked window
  com.android.internal.policy.impl.PhoneWindow$DecorView@4479b710 that
  was originally added here</p>
</blockquote>

<p>The app shows a progress dialog when the main activity starts and starts a task. When the task is done, it will dismiss the progress dialog.</p>

<p>My code is like below. Can someone help me?</p>

<pre><code>public class MyActivity extends Activity {

private static int ID_DIALOG_PROGRESS = 2001;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    setContentView(R.layout.my_activity);
    showDialog(ID_DIALOG_PROGRESS);
    new MyTask().execute(null, null, null);
}

@Override
protected Dialog onCreateDialog(int id) {
    if (id == ID_DIALOG_PROGRESS) {
        ProgressDialog loadingDialog = new ProgressDialog(this);
        loadingDialog.setTitle("");
        loadingDialog.setMessage("");
        loadingDialog.setIndeterminate(true);
        loadingDialog.setCancelable(false);
        return loadingDialog;
    }

    return super.onCreateDialog(id);
}

private class MyTask extends AsyncTask&lt;Void, Void, Void&gt; {

    @Override
    protected Void doInBackground(Void... arg0) {

            /* Do something expensive here...*/

            /* Start other activity*/
            Intent intent = new Intent(MyActivity.this, OtherActivity.class);
            startActivityForResult(intent, 1000);
        }

        return null;
    }

    protected void onPostExecute(Void arg0) {
        dismissDialog(ID_DIALOG_PROGRESS);
    }
}
}
</code></pre>

<p>Most of the time, the exception was thrown from showDialog() call. The other time, the exception was thrown from dismissDialog() call.</p>

<p>Thank you in advance!</p>
