6

My Application Flow:

Login->Profile->UpdateProfile->ChangePass

All of my activitys extends FragmentActivity

When I press button in ChangePass Activity I call this code:

Intent intent=new Intent(getApplicationContext(),LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

So It should start LoginActivity and when I press back from LoginActivity then Application should close...But When I press back button from Login Activity the flow is:

ChangePass->UpdateProfile->Profile->Login

Why My back stack is not cleared ?

Note:

I have applied all these solutions but not working: 1.link 2.link

Community
  • 1
  • 1
Vibhor Bhardwaj
  • 3,071
  • 5
  • 28
  • 49

4 Answers4

4

Very late reply though.
But might help others as it worked for me.

Developers sometimes confuse FLAG_ACTIVITY_CLEAR_TASK with FLAG_ACTIVITY_CLEAR_TOP

Use this instead
intentRestart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

Salmaan
  • 3,543
  • 8
  • 33
  • 59
2

Try the following way -

 Intent intent = new Intent(getActivity(), LoginActivity.class);
 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
 intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
 startActivity(intent);
 finish();

For more alternatives and details check intent-flag-activity-clear-top-doesn't-deletes-the-activity-stack. The post explains with the result code perfectly and with the above solution.

Community
  • 1
  • 1
sjain
  • 23,126
  • 28
  • 107
  • 185
0

Instead of replacing the old flags try appending one. Setflag replace theold flags.

Try using addFlags.

Android14
  • 1,045
  • 1
  • 11
  • 18
0

Clear the task and create new.

 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)

This might create a temporary white screen while transition. To remove this defect. Add this to your App theme.

<item name="android:windowDisablePreview">true</item>

Enjoy Android!

Shahbaz Ahmed
  • 459
  • 6
  • 9