简体   繁体   English

完成旧的A活动后如何开始A活动

[英]how to start A activity after finish old A activity

I tried to set intent.setFlags (FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_NEW_TASK) , but the effect is not as I think. 我试图设置intent.setFlags (FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_NEW_TASK) ,但是效果不像我想的那样。

It will execute onResume () in the old A activity. 它将在旧的A活动中执行onResume()。

But I want the effect as shown below: 但我想要如下所示的效果:

A activity onCreate() ... onPause() 活动onCreate()... onPause()

anywhere(from notification, from B activity ...) start A activity again 任何地方(从通知,从B活动...)再次开始A活动

old A activity onDestory() 旧的活动onDestory()

create new A activity 创建新的A活动

use (FLAG_ACTIVITY_CLEAR_TOP) flag when u passing intent. u传递意图时使用(FLAG_ACTIVITY_CLEAR_TOP)标志。 then after startactivity() use finish() method. 然后在startactivity()之后使用finish()方法。

you should use FLAG_ACTIVITY_CLEAR_TOP 您应该使用FLAG_ACTIVITY_CLEAR_TOP

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent. 如果已设置,并且正在启动的活动已经在当前任务中运行,那么与其启动该活动的新实例,不如关闭该活动之上的所有其他活动,并将此Intent传递给(现在顶部)将旧活动作为新的Intent。

SAMPLE CODE 样本代码

Intent i = new Intent(YourActivity.this, OTHERACTIVITY.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM