[英]Using flags for controlling activity lifecycle
Supposing I have the following activities: 假设我有以下活动:
A calls B, B calls C and C calls D, so my stack is, from top to bottom, DCBA. A调用B,B调用C,C调用D,所以我的堆栈从上到下都是DCBA。
Now I want call from D the activity B in order to obtain the following stack: 现在我想从D调用活动B以获得以下堆栈:
BA BA
Where B is not the previous instance that was in the initial stack configuration (DCBA) but is a new instance. 其中B不是初始堆栈配置(DCBA)中的先前实例,而是新实例。
What FLAG_ACTIVITY_
I have to use? 我必须使用什么
FLAG_ACTIVITY_
?
I have tried using this : 我试过使用这个:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
But this give me the old instance of Activity B, on top of the stack. 但这给了我堆栈顶部的活动B的旧实例。
Take out the flag Intent.FLAG_ACTIVITY_SINGLE_TOP. 取出标志Intent.FLAG_ACTIVITY_SINGLE_TOP。 From the docs :
从文档 :
The currently running instance of activity B in the above example will either receive the new intent you are starting here in its onNewIntent() method, or be itself finished and restarted with the new intent. 在上面的示例中,活动B的当前正在运行的实例将通过onNewIntent()方法接收您在此处开始的新意图,或者自行完成并使用新意图重新启动。 If it has declared its launch mode to be "multiple" (the default) and you have not set FLAG_ACTIVITY_SINGLE_TOP in the same intent, then it will be finished and re-created;
如果已将其启动模式声明为“多个”(默认),并且您未将FLAG_ACTIVITY_SINGLE_TOP设置为相同的意图,则它将完成并重新创建;否则,它将重新创建。 for all other launch modes or if FLAG_ACTIVITY_SINGLE_TOP is set then this Intent will be delivered to the current instance's onNewIntent().
对于所有其他启动模式,或者如果设置了FLAG_ACTIVITY_SINGLE_TOP,则此Intent将被传递到当前实例的onNewIntent()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.