11 Vote

Android Programming: Close entire App

Question by Guest | Last update on 2021-05-12 | Created on 2016-06-12

I am searching for a Java command for Android with which I can quit and exit my whole app programmatically.

Up to now, I have always used finish(), but this function only seems to close the current activity and not all of the application.

What can I do if my app is consisting of multiple activities?

ReplyPositiveNegative
1Best Answer1 Vote

If you want to work with finish(), you have to call finish() for each activity individually to close all.

To close all activities at once, you can use the following line since API 16:

this.finishAffinity();

With this, you are closing the current activity as well as all activities below in the same task having the same affinity.

By the way, the android developers have not necessarily intended that someone is about to exit an app via code. Instead, this should handle and manage the system.
Last update on 2021-05-12 | Created on 2016-06-13

ReplyPositive Negative
Reply

Related Topics

Android Splash Screen Tutorial

Tutorial | 0 Comments

Android Getting Sound Levels

Open Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.