My app shows a signup activity the first time the user runs the app, looks like:
- ActivitySplashScreen (welcome to game, sign up for an account?)
- ActivitySplashScreenSignUp (great, fill in this info)
- ActivityGameMain (main game screen)
so the activities launch each other in exactly that order, when the user clicks through a button on each screen.
When the user goes from activity #2 to #3, is it possible to wipe #1 and #2 off the history stack completely? I'd like it so that if the user is at #3, and hits the back button, they just go to the homescreen, instead of back to the splash screen.
I think I can accomplish this with tasks (ie. start a new task on #3) but wanted to see if there was simpler method,
Thanks
I use this way.
You can use forwarding to remove the previous activity from the activity stack while launching the next one. There's an example of this in the APIDemos, but basically all you're doing is calling
finish()
immediately after callingstartActivity()
.This is likely not the ideal way to do it. If someone has a better way, I will be looking forward to implementing it. Here's how I accomplished this specific task with pre-version-11 sdk.
in each class you want to go away when it's clear time, you need to do this:
then the one that needs to set off the chain of pops from the stack needs to just call this when you want to initiate it:
Then the activities aren't on the stack!
Remember folks, that you can start an activity, and then begin cleaning up behind it, execution does not follow a single (the ui) thread.
Just call this.finish() before startActivity(intent) like this-
for API >= 15 to API 23 other solution not works in my case . finally i get this one.
Try this:
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)
it is API Level 1, check the link.