title: How to clear the Android Stack of activities?
body: <p>I have an application with several Activities in Android and I want the user to be able to log-out by pressing a menu button. The problem I have is that</p>
  
  <p>A) Android doesn't let you terminate the application and<br>
  B) even when I send the user to the <code>LoginActivity</code> again they can always press <em>back</em> and get right back to the previous activity they were in.</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>I also tried with each one of them by themselves.</p>
  
  <p>I also tried calling <code>finish()</code> after <code>startActivity(intent)</code> as I read in another StackOverflow
  question.</p>