0

I start with showing the workflow graph of my app enter image description here

Firstly, when app is lunched the checker is created, this activity check if user is logged or not, if not it goes to log_1 activity and checker activity is finished. Then the user choose the method in log1 -> put login data in log2 -> the system checks if the values are correct and here is start activity with FLAG_ACTIVITY_CLEAR_TOP when i'm going to menu1. And when I click back button I exit the app so it works like it should. code for intent with flag:

Intent intent = new Intent(LoginStation.this, ChooseMenu.class);
             //clears all activities in stack, and we only have acitivity which we going to 
             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
             startActivity(intent);

In every screen of menu I got the action bar with button log out and when I click it, the log1 screen is created with FLAG_ACTIVITY_CLEAR_TOP but now when I click the back button it goes back to menu screen instead of exit the app.

My goal is to when the user go to menu1 or log1 screen the backstack should be clear, but apparently I made some mistakes and I have no idea where. If i go from log3 to menu back stack is cleared, when I use this same method to go from menu to log1 screen it doesn't clear backstack.

Kaushik
  • 6,150
  • 5
  • 39
  • 54
MyWay
  • 1,011
  • 2
  • 14
  • 35

1 Answers1

2

Add this code for clearing the stack Difference between addFlags and setFlags

Intent intent = new Intent(LoginStation.this, ChooseMenu.class);
//clears all activities in stack, and we only have acitivity which we going to 
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

More info about it

Community
  • 1
  • 1
Kaushik
  • 6,150
  • 5
  • 39
  • 54
  • it doesn't work, if user is already logged and he goes straight to manu1, cause the flag firstly need to be added. I try something with adding flag in checker – MyWay Jan 31 '14 at 14:12