title: Android: Clear Activity Stack
body: <p>I'm having several activities in my application. and flow is very complicated. When I click the Logout application navigates to login Screen and from there user can exit by cancel button (calling <code>system.exit(0)</code> )</p>
  
  <p>when I exit or back button, the system invokes an activity from stack :( how can I clear all the activities in the stack when I reach Login screen? calling <code>finish()</code> is not practical as there are so many activities and some activities should no be closed when they are active such as native camera invoking activity.</p>
  
  <pre><code>validateuser logoutuser = new validateuser();
  logoutuser.logOut();
  Intent loginscreen = new Intent(homepage.this, Login2.class);
  (homepage.this).finish();
  loginscreen.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
  startActivity(loginscreen);
  </code></pre>