Robertoq
Robertoq

Reputation: 704

Android close all activity when sing out

In my app have a sign in activity. If login is successful, I start the first activity. It includes the menu, which opens ActivityA, ActivityB, ActivityC... and from these activities I can go deeply ActivityASubA and deeper ActivityASubB...

-ActivityA
--ActivityASubA
--ActivityASubB

-ActivityB
--ActivityBSubA
--ActivityBSubB

...

And if the user open ActivityA and ActivityASubA and later from the menu ActivityB and after that sign out, I open the sign in activity, but in the history will be the previous activities and if he press back see again these activities and it's a problem.

So when sign out I need to close all activity. Which is the best solution?

Upvotes: 1

Views: 322

Answers (1)

Alex Klimashevsky
Alex Klimashevsky

Reputation: 2495

In sign out method you should put this code:

Intent intent = new Intent(this, Home.class);  
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
startActivity(new Intent(this, Home.class));  
finish();  

About FLAG_ACTIVITY_CLEAR_TOP you can read th

Upvotes: 1

Related Questions