Clear back navigation stack on activity intent
<p>I have a login view at the start of my application. On logging in this view is finished manually (i.e. <code>finish()</code> is called in the code). This is so that the user doesn't have to press the back button past the login page when they want to exit the app.</p>

<p>Now I want to have a <code>logout</code> button in the app. This calls the login view (with an intent to remove any previously stored login credentials - i.e. simulating a logout).</p>

<p>What I need to do is clear the backwards navigation stack on this intent, or else the user will still be able to press back and view the application as they navigated it originally.</p>

<p>Now, <code>Intent.FLAG_ACTIVITY_CLEAR_TOP</code> doesn't work, I presume because I <code>finish()</code> the Login activity meaning that that activity isn't in the back stack. I am also using <code>Intent.FLAG_ACTIVITY_NEW_TASK</code> which doesn't seem to work either. User's can still press the back button and navigate backwards through activities they should be logged in to access.</p>

<p>So what I need to do is create an instance of the Login activity and make this the new <code>root</code> activity of my application.</p>

<p>How can I do this?</p>

<p>Thanks</p>
