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?