Android的单身活动 [英] android singleton activity
问题描述
应用程序的主要活动是TabActivity包含一些OneActivity
The main activity of the app is TabActivity that contains some OneActivity
这是需要从应用程序的其他部分调用OneActivity没有创造它的另一个实例, 只是调用一个位于TabActivity的onResume()
It is necessary to call from another part of app the OneActivity not creating the another instance of it, just calling onResume() of the one that lies in TabActivity
尝试设置不同的launchMode(singleTop,singleTask,singleInstance),并设置标志的意图:
Tried set different launchMode ("singleTop", "singleTask", "singleInstance") and set flags for intent:
intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER);
如何做到这一点没有创造活动的一个新实例?
How to do it not creating a new instance of activity?
推荐答案
尝试 CLEAR_TOP
标志。我删除所有上述活动您在活动栈的活动,所以它应该可以解决你的目的。
Try the CLEAR_TOP
flag. I removes all the activities above your activity in the activity stack, so it should solve your purpose.
Intent i = new Intent(context, YourSingleInstanceActivityName.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
这篇关于Android的单身活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!