Removing an activity from the history stack

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


    You can achieve this by setting the android:noHistory attribute to "true" in the relevant <activity> entries in your AndroidManifest.xml file. For example:

    <activity
        android:name=".AnyActivity"
        android:noHistory="true" />
    

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


    是的,看看Intent.FLAG_ACTIVITY_NO_HISTORY。

    链接地址: http://www.djcxy.com/p/26208.html

    上一篇: 如何在Android上将对象从一项活动传递给另一项活动

    下一篇: 从历史堆栈中删除活动