Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close app when hitting back button on android

So my login Activity is the first screen you see. When you hit the back button, it exits the app, good. So I open up the app again. After logging in, I am now in my main Activity. How do I make it so when I hit the back button now, it exits the app rather than going back to the login Activity?

like image 504
Ronnie Avatar asked May 05 '11 18:05

Ronnie


1 Answers

When you push the new activity, call finish() on the previous, otherwise it will remain on the stack, therefore appearing when you hit back and pop the current activity.

Hope that helps.

like image 95
Oh Danny Boy Avatar answered Sep 30 '22 06:09

Oh Danny Boy