Switching between activities in android?

前端 未结 7 586
有刺的猬
有刺的猬 2020-12-18 10:22

In my android application, I have following requirement.

Activity A --> Activity B(Go to A Option) --> Activity C(Go To A Option,Go To B Option)

<
7条回答
  •  渐次进展
    2020-12-18 10:53

    I assume that you don't want to use Intent because whenever you use Intent for moving to activity A pressing Back key will move to the previous activity (activity C). In this case I would suggest you to include FLAG_ACTIVITY_CLEAR_TOP flag. It will destroy all the previous activity and let you to move to Activity A.

     Intent a = new Intent(this,A.class);
     a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     startActivity(a);
    

    Alternatively, you can try the FLAG_ACTIVITY_REORDER_TO_FRONT flag instead, which will move to activity A without clearing any activity.

    For more, check this.

提交回复
热议问题