title: closing application on hardware back button in android
body: <p>I have seen a bunch of posts like this, but none of the solutions has worked for me. I have an app, where the first thing that is loaded is the LoginActivity, it checks to see if you are already logged in, if you are it send you to the MainActivity, which is the main meat of the application. My problem is, when you are on the MainActivity and you hit the hardware back button, it just reloads the MainActivity because, I'm assuming it tries to go "back" to the LoginActivity.</p>
  
  <p>I have tried various "fixes" from posts I have seen on here, but none of them seem to work. Currently in the AndroidManifest.xml file for my MainActivity I have added the </p>
  
  <blockquote>
    <p>android:noHistory="true"</p>
  </blockquote>
  
  <p>To the MainActivity intent, but that isn't making much of a difference. I have seen another post where someone mentioned basically starting a new Activity with a special Intent that makes the system load your home screen, but someone pointed out that if someone loads your app, hits back, then does it again it keeps adding to the "stack" and that can be very bad.</p>
  
  <p>So I am hoping someone has encountered something similar, where you have to have the LoginActivity load first to verify the user, then that launches Main, but then you need to kill the app on back button press from the MainActivity.</p>
  
  <p>Thank you for any help in advance. I appreciate it.</p>