How can I exit from my app?
I want that when the user will clicked on the button, the app will exit completely, I saw any answers about it, but they took the app to back
in this method you have can call exit()
function anywhere and get exit from the app. so For closing an app at any point use FLAG_ACTIVITY_CLEAR_TOP
flag in Intent & then system.exit();
NOTE : I think in way it will not break the Android Life cycle
In a place where you need to execute EXIT from the app
public void exit() {
startActivity(new Intent(this, HomeActivity.class).
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK).putExtra(EXIT_FLAG, true));
}
MainActivity.onCreate()
protected void onCreate(Bundle savedInstanceState) {
if (getIntent().getBooleanExtra(EXIT_FLAG, false)) {
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
finish();
}
}