Issue
On my App, I have the following process to log on a user:
The user enters its credentials on the
MainActivity
and is redirected toHomeActivity
using that code for navigation:Intent accueilIntent = new Intent(getApplicationContext(), HomeActivity.class); accueilIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); finish(); startActivity(accueilIntent);
When the user is on the
HomeActivity
, he is able to log out thanks to a log out button. Since the event is fired, I would like to kill all activities and redirect the user to the login activity (MainActivity
). So The code which is fired on the event is the following:Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent);
The user is well redirected to the
MainPage
. Then when I press the home button to get back on the Android home screen and then I come back to the App, the rightMainActivity
appears. However, when I press the native back button to return to the android home screen and then I come back to the App, theHomeActivity
appears (the one that should be destroyed before) and not theMainActivity
.
Does anyone can tell me why I'm coming back to HomeActivity
and not MainActivity
in this case?
Solution
1] add finish()
before startActivity()
2] Add FLAG_ACTIVITY_NO_HISTORY
flag.
Intent intent = new Intent(mContext, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
Answered By - Prachi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.