Reputation: 1241
I am building an app which uses either some activities in which the user can navigate or uses one specific activity which starts the app when a deeplink is used. In this DeeplinkActivity I have a button with which the app should exit the entire app and not put it into the background. I tried the following code, which only closes the app, but it still remains in the background?!
public void onStopButton(View view) {
log.info("UI -> Stop this app");
// this.finishAffinity();
android.os.Process.killProcess(android.os.Process.myPid());
// finish();
System.exit(0);
}
I tried all kinds of suggested combinations, but none of them really exits the app. Anybody have some other (working) code suggestions? I have set minSdkVersion=19 and targetSdkVersion=26
Upvotes: 1
Views: 492
Reputation: 1006674
First, note that having a button such as you describe is considered to be an anti-pattern in Android.
That being said, if your minSdkVersion
is 21 or higher, replace your onStopButton()
with:
public void onStopButton(View view) {
finishAndRemoveTask();
}
If your minSdkVersion
is lower than 21, there are some clunky workarounds that I do not recommend.
Upvotes: 0