I have a splash screen activity, then a login activity. My history stack looks like:
SplashActivity LoginActivity
when the user successfully logs in via LoginActivity, I want to start WelcomeActivity, but clear the entire stack:
SplashActivity LoginActivity // launches WelcomeActivity -> WelcomeActivity // but now all three are in the history stack, while I only // want WelcomeActivity in the stack at this point.
Is there some flag I can use to do that?
// LoginActivity.java Intent intent = new Intent(this, WelcomeActivity.class); intent.addFlag(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); finish();
Not sure if using the FLAG_ACTIVITY_CLEAR_TASK will clear out all activities in my task or not. I can do this 'manually' by unwinding the stack by using startActivityForResult() calls, but will be more fragile and more code to maintain.
Thanks
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
Just open the perspective Windows->Open Perspective-> Hierarchy View In the list you can see the all the connected devices and emulators and the activity stack.
Yes that should work fine. You could use:
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_SINGLE_TOP
FLAG_ACTIVITY_CLEAR_TASK
FLAG_ACTIVITY_NEW_TASK
which ensures that if an instance is already running and is not top then anything on top of it will be cleared and it will be used, instead of starting a new instance (this useful once you've gone Welcome activity -> Activity A and then you want to get back to Welcome from A, but the extra flags shouldn't affect your case above).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With