Android View not attached to window manager (dialog dismiss)
<p>java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{41c2e378 V.E..... R......D 0,0-450,161} not attached to window manager</p>

<p><strong>MainActivity:</strong>  </p>

<pre><code>   Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                       startActivity(intent);
                        finish();    
</code></pre>

<p><strong>SecondActivity</strong></p>

<pre><code> new SetEntrySent(SecondActivity.class, false).execute(id);

 Intent intent = new Intent(SecondActivity.this, MainActivity.class,);
                           startActivity(intent);
                            finish();   
</code></pre>

<p><strong>CreateEntry Async</strong>
<strong>onpostexecute</strong></p>

<pre><code> dialog.dismiss();
}//finishing class
</code></pre>

<p><strong>MainActivity:</strong>  </p>

<pre><code> **onresume**

//checks again and if entry not sent, it also calls:
   new SetEntrySent(SecondActivity.class, false).execute(id);
</code></pre>

<p>for</p>

<pre><code> dialog.dismiss();
</code></pre>

<p>it gives errors.</p>

<blockquote>
  <p>Process: com.example..androidwithlogin, PID: 27426
                                                                                           java.lang.IllegalArgumentException:
  View=com.android.internal.policy.impl.PhoneWindow$DecorView{41c2e378
  V.E..... R......D 0,0-450,161} not attached to window manager</p>
</blockquote>

<p>First, main activity calls second activity. Second activity, after operations call asynctask and at same time finishes and intents to mainactivity.</p>

<p>When i do without <code>finish()</code> it works.</p>

<p>i can intent mainactivity from asynctask, but how secondactivity will finish? asynctask has context of secondactivity. Can it finish it?</p>

<p>i searched and found this</p>

<pre><code>   private void dismissProgressDialog() {
    if (pDialog != null &amp;&amp; pDialog.isShowing()) {
        pDialog.dismiss();
    }
}
</code></pre>

<p>and it works for this.</p>

<p>But because of async, asynctask is called a lot of times.</p>

<p>What is the best way to prevent this? If i put going to mainactivity to postexecute of async</p>

<p><strong>CreateEntry Async</strong>
<strong>onpostexecute</strong></p>

<pre><code> dialog.dismiss();
 Intent intent = new Intent(context, MainActivity.class,);
                           startActivity(intent);
                            finish();   
}//finishing class
</code></pre>

<p>can it finish secondactivity also and is that safe? because asynctask will be finishing, mainactivity can not call again it.</p>