Android: open activity without save into the stack

前端 未结 10 1915
暗喜
暗喜 2020-11-27 04:19

I have 2 activities: Main and List.

From Main you can open List; from List you can open Main.

I\'d like it so that every opening of List does not

10条回答
  •  鱼传尺愫
    2020-11-27 05:21

    When starting your list's Activity, set its Intent flags like so:

    Intent i = new Intent(...); // Your list's Intent
    i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY); // Adds the FLAG_ACTIVITY_NO_HISTORY flag
    startActivity(i);
    

    The FLAG_ACTIVITY_NO_HISTORY flag keeps the new Activity from being added to the history stack.

    NB: As @Sam points out, you can use i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); instead. There is no functional difference.

提交回复
热议问题