tags:

views:

562

answers:

3

Hi,

My app shows a signup activity the first time the user runs the app, looks like:

  1. ActivitySplashScreen (welcome to game, sign up for an account?)
  2. ActivitySplashScreenSignUp (great, fill in this info)
  3. 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

+2  A: 

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 calling startActivity().

Daniel Lew
Hi Daniel, I read through the example, but that will only clear the history stack by 1 activity, won't it? If my stack looks like A, B, and I'm launching C, I want C to be the new root and completely clear A and B. In the sdk example, calling finish() from B would leave me with a stack of A, C, wouldn't it? Thanks.
Mark
You could clear A as you launch B, and clear B as you launch C; however, I suppose then you wouldn't be able to back out from B to A if that's what you desire. I'll have to think on this more if that's a problem.
Daniel Lew
+2  A: 

Yes, have a look at Intent.FLAG_ACTIVITY_NO_HISTORY.

Matthias
A: 

So what I need can be done with startActivityForResult() and onActivityResult(). I just needed to decide a history path my activities can take, and call finish() when the user performs an action that should 'unwind' my activity stack.

Thanks

Mark