【发布时间】:2014-09-28 17:30:49
【问题描述】:
如文档所述,如果该活动在清单中设置了 launchMode="singleTop",则意图将通过 onNewIntent 回调进入。
当活动由 TabHost 启动时,我无法获得此行为。不是调用 onNewIntent,而是调用 Activity 的 onCreate 方法,从而在 Activity 堆栈顶部生成一个新的 Activity 实例。
这是我启动意图的代码:
// create the TabHost that will contain the Tabs
tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec tab1 = tabHost.newTabSpec("First Tab");
TabSpec tab2 = tabHost.newTabSpec("Second Tab");
TabSpec tab3 = tabHost.newTabSpec("Third tab");
// Set the Tab name and Activity
// that will be opened when particular Tab will be selected
tab1.setIndicator("Tab1");
Intent intent = new Intent(this, WhenLogin.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
Intent.FLAG_ACTIVITY_SINGLE_TOP);
tab1.setContent(intent);
还有其他人遇到过这个问题吗?如果有,他们找到解决办法了吗?
【问题讨论】:
-
“由
TabHost开始”是什么意思? -
我正在使用标签。当我不使用标签时一切正常。
-
也许您可以考虑粘贴到您的源代码中来解释“由
TabHost开始”的意思。 -
我编辑了我的代码,感谢重播。
标签: java android android-intent nfc