Android:如何避免开始已经在堆栈中的活动? [英] Android: How do I avoid starting activity which is already in stack?
问题描述
让我们尝试解释我的问题: 我有一个应用程序和服务. 该应用程序以活动A启动. 该服务发送广播,该广播将使应用程序启动活动B 现在,用户开始活动C.
Lets try to explain my question: I got an application and a service. The application is started with activity A. The service sends a broadcast that will let the application start Activity B Now the user starts activity C.
现在,该服务希望再次开始活动B.但是我如何让他知道活动仍在堆栈中,或者是否有意图标记?
Now the service wants to start activity B again. But how do I let him know that the activity is still on the stack, or is there an intent flag for this?
如何避免由于活动B已经在堆栈中而启动活动B?
How do I avoid that it will launch activity B because its already in the stack?
推荐答案
我认为您需要进行活动B singleInstance
,如果活动B已创建,则您不想再创建,即android:launchMode中定义http://developer.android.com/guide/topics/manifest/activity-element.html#lmode"rel =" noreferrer>活动的启动模式,该清单定义了如何活动将被实例化..
I think you need to make your activity B singleInstance
that if it's already create you don't want to create again, that is launch mode of the activity can be defined in manifest android:launchMode
that defines how the activity will be instanciated.
在您的情况下,请使用android:launchMode="singleInstance"
in your case use android:launchMode="singleInstance"
这篇关于Android:如何避免开始已经在堆栈中的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!