I want my app to exit completely, even from background.
Firstly, quick explanation of my app:
I have the following activity:
Launcher -> Main -> A -> B -> C
When I open app, I fire off the launcher, checks if I have logged in before (this is usually the case, answer is yes, I'm logged in), finish() -> move to Main screen, (answer a question in main) -> move to A (..) -> move to B (...) -> move to C
without using any finish between Main, A, B and C.
in C I have exit button, I want it to exit the app completely.
Here is my code:
Launcher:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkIfUserLoggedIn();
//some other code
}
private void checkIfUserLoggedIn() {
String codeStr = DatabaseMgr.getPreferences(getString(R.string.savedCode), this);
if (codeStr != null && !codeStr.isEmpty()) {
moveToMainScreen();
}
}
private void moveToMainScreen() {
Intent intent = new Intent(MainActivity.this, MainScreen.class);
startActivity(intent);
finish();
}
from Main -> A -> B -> C ==> same code as:
Intent intent = new Intent(<ACT>.this, <Next ACT>.class);
startActivity(intent);
pressing exit in C:
Intent intent = new Intent(getApplicationContext(), MainScreen.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
MainScreen Activity:
if (getIntent().getBooleanExtra("EXIT", false)) {
//1- this.finishAffinity();
//2- finish()
//3- Intent i = new Intent();
//i.setAction(Intent.ACTION_MAIN);
//i.addCategory(Intent.CATEGORY_HOME);
//ListActivity.this.startActivity(i);
//finish();
//4- android.os.Process.killProcess(android.os.Process.myPid());
return;
}
all of the above attempts leave me this on phone:
what am I doing wrong?
is there any other way to exit application completely ? not even keeping it as in attached picture ??
Thanks alot!