在默认的android启动器中,在另一个活动中按Home键将启动启动器。在启动程序中再次按home将重置为默认的主页页面。我不明白这是怎么做到的。无论launcher是否在前台,Android都会发送相同的意图。Home键也不能被用户应用拦截。
有没有办法做到这一点?
发布于 2012-11-03 06:21:37
无论launcher是否在前台,
Android都会发送相同的意图。
对,是这样。
主页密钥也不能被用户应用程序拦截。
对,是这样。
我不明白怎么能做到这一点。
如果对startActivity()的调用将导致Intent被传递到该活动的现有实例,则不会创建新实例(根据定义),并且使用onNewIntent()而不是onCreate()调用现有实例。
在主屏幕的情况下,通常是主屏幕的活动将在清单中使用android:launchMode="singleTask"或android:launchMode="singleInstance",例如:
<activity
android:name="Launcher"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/Theme"
android:screenOrientation="nosensor"
android:windowSoftInputMode="stateUnspecified|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
</intent-filter>
</activity>(来自an old launcher in the AOSP)
然后,该活动可以实现onNewIntent()来做一些事情。在前面提到的旧启动程序的情况下,its onNewIntent() includes
if (!mWorkspace.isDefaultScreenShowing()) {
mWorkspace.moveToDefaultScreen();
}如果用户当前正在观看由主屏幕活动管理的屏幕集合中的某个其他屏幕,则这大概使UI动画回到默认屏幕。
触发onNewIntent()的另一种方法不是使用android:launchMode,而是在调用startActivity()时有选择地执行,方法是在Intent中包含适当的标志,如FLAG_ACTIVITY_REORDER_TO_FRONT。
发布于 2014-02-16 12:58:26
更具体地说,请执行以下操作
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) !=
Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) {
goHome();
}
}https://stackoverflow.com/questions/13203536
复制相似问题