My app is intended to allow only logged in user to access the activities. If a user logs out, the Shared preference boolean isLogged in is set to false and the user should not access the rest of activities except the LoginActivity.
However, I am able to access all the previously opened activities by pressing the back button.
I would use finish();
while opening each activity but then I would like users to still use the back button while they're logged in.
I have tried solutions from other similar questions like
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
and on the onCreate()
of my LoginActivity I have added
if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
}
When I press the logout option, the previous activity opens instead.
Any suggestions please help me?
Close all apps: Swipe up from the bottom, hold, then let go. Swipe from left to right. On the left, tap Clear all. Close all apps on Android Go: Swipe up from the bottom, hold, and let go.
To Close the Application, you can also take "System. exit(0)" 0 is standard or use any exit code.
In order to check when the 'BACK' button is pressed, use onBackPressed() method from the Android library. Next, perform a check to see if the 'BACK' button is pressed again within 2 seconds and will close the app if it is so.
You should use this flags, that clear your TASK and create a new one
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With