Android的新意图()启动新的实例与Android:launchMode =" singleTop" [英] Android: new Intent() starts new instance with android:launchMode="singleTop"
本文介绍了Android的新意图()启动新的实例与Android:launchMode =" singleTop"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有活动 A
与安卓launchMode =singleTop
在清单
如果我去到活动 B
, C
和 D
有我的菜单快捷键,返回到我的应用程序根系活力( A
)。
If I go to Activity B
, C
and D
there I have menu shortcuts to return to my applications root activity (A
).
在code是这样的:
Intent myIntent = new Intent(getBaseContext(), MainActivity.class);
startActivity(myIntent);
不过,而不是返回到已存在的实例 A
我的 MainActivity.class
它会创建一个新的实例 - >则进入的onCreate()
而不是 onNewIntent()
。
However, instead of returning to the already existing instance A
of my MainActivity.class
it creates a new instance -> it goes to onCreate()
instead of onNewIntent()
.
这是不是预期的行为,对吧?
This is not the expected behavior, right?
推荐答案
这应该可以解决问题。
<activity ... android:launchMode="singleTop" />
当你创建一个意图启动应用程序的使用:
When you create an intent to start the app use:
Intent intent= new Intent(context, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
这是应该是必要的。
这篇关于Android的新意图()启动新的实例与Android:launchMode =&QUOT; singleTop&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文