basically my app has a loginScreen and once logged u can go through many activities. when i press the home button the app goes in background and if the user doesnt open it within a certain amount of time, the users session closes and u return to the loginScreen. now the problem is that if i want to close the app from the loginScreen once my session has expired i press the back key and it should close but it doesnt. it brings me to the previous element in the stack.
the wired thing is that on all onBackPressed() methods and when ever i started new intents i always use intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
and on the loginScreen onBackPressed() i call finish()
but it doesnt work. anyone know why? and how do i solve this problem.
Thanks for the help!!!
code snippets in many activities:
@Override
public void onBackPressed() {
mpButtonClick.start();
Intent intent = new Intent(this, MenuPagina.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
super.onBackPressed();
}
in the loginActivity:
@Override
public void onBackPressed() {
super.onBackPressed();
getIntent().setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
LoginActivity.this.finish();
}
When starting an activity that I don't want to be included in the BackStack I use:
I have read (on here somewhere) about onBackPressed() not calling and instead they used onKeyPressed and specified the back button. I'll see if I can find the example.
Here is the example: Android - onBackPressed() not working
You can do this two way:
android.os.Process.killProcess(android.os.Process.myPid());
on back press.for this you need to add below permission on manifest.
2 . use static boolean 'isKill' variable with default false and every time set false in login activity oncreate() method.
set isKill value true in login activity onBackPress() method.
And then write below code in every activity onResume() method