How to clear the activity stack in android?
<p>I'm having a requirement where i can press a logout button from any activity in the application,the thing is when I press the logout button I need to get the <code>login</code> screen without showing the previous activities. I am using:</p>

<pre><code>intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP )
</code></pre>

<p>I am starting the activity like this:</p>

<pre><code>public void onClick(View v) {
  try
  {
      Intent intent = new Intent(getContext(), Login.class);
      v.getRootView().getContext().startActivity(intent);
      intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );
      removeSessionFiles();
      //startActivity (new Intent(getApplicationContext(), Activity1.class));
  }
  catch (Exception e)
  {
    String str = e.toString();
  }
}
</code></pre>

<p>I get to the <code>login</code> screen when I press the <code>logout</code> button, but when I press <code>back</code> button on the device it is showing the previous activities - I should go to the Android home screen when I press back button in the <code>login</code> screen. Please can you suggest a solution for this?</p>
