Clear the Activity stack when I go to an activity
<p>I am working on an application with several Activities, problem is that I want the user to be able to log out by pressing a button.</p>

<p>Suppose we have 4 Activity named A,B,C,D. Navigation of the activity like B->C->D.  </p>

<p>On Activity D user have options for logout. When user click on the Logout button the he go to Activity A which is not called in the navigation. Now, user click on the back button then he got to previous activity like Activity D.</p>

<p>I already tried to launch the Activity with the two following flags: </p>

<pre><code>Intent intent = new Intent(this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        
startActivity(intent);
</code></pre>

<p>Can anyone help?</p>
