When a user presses the back button on an intent, the application should quit. How can I ensure the application quits when the back button is pressed?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Immediately after you start a new activity, using
startActivity, make sure you callfinish()so that the current activity is not stacked behind the new one.EDIT
With regards to your comment:
What you’re suggesting is not particularly how the android app flow usually works, and how the users expect it to work. What you can do if you really want to, is to make sure that every
startActivityleading up to that activity, is astartActivityForResultand has anonActivityResultlistener that checks for an exit code, and bubbles that back. You can read more about that here. Basically, usesetResultbefore finishing an activity, to set an exit code of your choice, and if your parent activity receives that exit code, you set it in that activity, and finish that one, etc…