Removing an activity from the history stack

后端 未结 15 949
[愿得一人]
[愿得一人] 2020-11-22 08:28

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. Activ
相关标签:
15条回答
  • 2020-11-22 09:00

    Just set noHistory="true" in Manifest file. It makes activity being removed from the backstack.

    0 讨论(0)
  • 2020-11-22 09:02

    It's too late but hope it helps. Most of the answers are not pointing into the right direction. There are two simple flags for such thing.

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    

    From Android docs:

    public static final int FLAG_ACTIVITY_CLEAR_TASK Added in API level 11

    If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the
    

    activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.

    0 讨论(0)
  • 2020-11-22 09:04

    Just call this.finish() before startActivity(intent) like this-

           Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
            this.finish();
            startActivity(intent);
    
    0 讨论(0)
  • 2020-11-22 09:05

    In the manifest you can add:

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

    You can also call

    finish()
    

    immediately after calling startActivity(..)

    0 讨论(0)
  • 2020-11-22 09:05

    Removing a activity from a History is done By setting the flag before the activity You Don't want

    A->B->C->D

    Suppose A,B,C and D are 4 Activities if you want to clear B and C then set flag

    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    

    In the activity A and B

    Here is the code bit

    Intent intent = new Intent(this,Activity_B.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(intent);
    
    0 讨论(0)
  • 2020-11-22 09:08

    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" />
    
    0 讨论(0)
提交回复
热议问题