I'm having several activities in my application. and flow is very complicated. When I click the Logout application naviagates to login Screen and from there user can exit by cancel buton (calling system.exit(0)
)
when I exit or back button, system invokes an activity from stack :( how can I clear all the activities in the stack when i reach Login screen? calling finish()
is not practical as there are so many activities and some activities should no be closed when they are active such as native camera invoking activity.
validateuser logoutuser = new validateuser();
logoutuser.logOut();
Intent loginscreen = new Intent(homepage.this, Login2.class);
(homepage.this).finish();
loginscreen.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(loginscreen);
This decision works fine:
But new activity launch long and you see white screen some time. If this is critical then use this workaround:
How use it:
Disadvantage: all activities that must be closed on the stack must extends BaseActivity
When you call
startActivity
on the last activity you could always useas a flag on that intent.
Read more about the flag here.
Most of you are wrong. If you want to close existing activity stack regardless of what's in there and create new root, correct set of flags is the following:
From the doc:
Here is a simple helper method for starting a new activity as the new top activity which works from API level 4 up until the current version 17:
call it like this from your current activity:
In my case, LoginActivity was closed as well. As a result,
did not help.
However, setting
helped me.
For Xamarin Developers, you can use: