I need to finish all the activities running in an Android application when an exit button is clicked. How can I do that?
What I want:
Delete all activity On your Android phone or tablet, go to myactivity.google.com. Above your activity, tap Delete .
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
Navigate to app>java>your app's package name>Right click on it>New>Empty Activity>Name it as >Main2Activity and click on Finish to create a new activity. Navigate to app > java > your app's package name > MainActivity file and add the code below. Comments are added in the code to get to know in detail.
I don't understand the people who say that this should not be done. Closing an activity can be done quite easily using the built in method to do so.
There is no place in the official documentation that says this should not be done.
For those who think it should not be done for any purpose, maybe you can't think of a reason to do so. There are plenty of legitimate reasons to do this. And since it is a method built in to the Android code.. Google has also decided that you might need to depending on your use. Not all of us only create consumer applications for Android.
So to accomplish this task..shutting down all of the activities in your stack
public void quitApp(){
this.finishAffinity();
}
I created a kiosk app that was run as the default launcher. So I needed a way to exit the app to get to settings or other apps on the device. So in an admin Activity, I placed a pin number pad.. after the user inputs the correct pin, the app needed to exit to the original launcher. I used above code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With