Removing an activity from the history stack

后端 未结 15 1128
[愿得一人]
[愿得一人] 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: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.

提交回复
热议问题