Issue
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?
Solution
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);
Answered By - Lucas Ferraz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.