Android launcher在launcher中按home键进入默认屏幕

Android launcher在launcher中按home键进入默认屏幕,android,android-intent,android-launcher,android-homebutton,Android,Android Intent,Android Launcher,Android Homebutton,在默认的android启动器中,在另一个活动中按home键将启动启动器。在启动程序中再次按home(主页)将重置为默认主页。我不明白怎么能做到这一点。无论启动器是否在前台,Android都会发送相同的意图。主密钥也不能被用户应用截获 有没有办法做到这一点 无论启动器是否在前台,Android都会发送相同的意图 对 主密钥也不能被用户应用截获 对 我不明白怎么能做到这一点 如果对startActivity()的调用将导致将Intent传递给活动的现有实例,则不会创建新实例(根据定义),并使用onN

在默认的android启动器中,在另一个活动中按home键将启动启动器。在启动程序中再次按home(主页)将重置为默认主页。我不明白怎么能做到这一点。无论启动器是否在前台,Android都会发送相同的意图。主密钥也不能被用户应用截获

有没有办法做到这一点

无论启动器是否在前台,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>
如果用户当前正在查看由主屏幕活动管理的屏幕集中的其他屏幕,则这可能会将UI动画化回默认屏幕


另一种触发
onNewIntent()
,而不是使用
android:launchMode
,是在调用
startActivity()
时有选择地触发,方法是在
Intent
中包含适当的标志,例如
标志活动\u重新排序\u到前面
更具体地说,是这样做的

@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();
    }
}

非常感谢你提供的信息。我尝试了另一种触发onNewIntent()的方法,即在带有或不带有FLAG_ACTIVITY_SINGLE_TOP的_FRONT中添加FLAG_ACTIVITY_REORDER_,但onNewIntent()未被触发。我有什么遗漏吗?Thanks@kevdliu:嗯。。。尝试组合使用
标记活动\u清除\u顶部
标记活动\u单个顶部
,然后。我知道这是可行的,因为我在我的一些NFC示例应用程序中使用它将NFC标记事件发送到正在运行的活动(而不是启动另一个副本)。我想
标记活动\u重新排序\u到\u前台
也会有同样的效果。请记住,只有当活动已经存在时才会调用
onNewIntent()
,如果您使用
finish()
或“后退”按钮来删除该活动,则必须创建一个新的活动,并调用
onCreate()
,而不是
onNewIntent()
。感谢您的回复。我接受了你的回答,因为它回答了我原来的问题。但我实际上是在尝试编写一个模拟home键启动行为的主屏幕启动程序。如果你能帮我,我将非常感激。我通过getLaunchIntentForPackage()获得了主屏幕的启动意图,添加了标志和startactivity()。但是,没有调用启动器的onNewIntent()。@kevdliu:那么您必须查看启动器的源代码,因为我不知道它可能在做什么。而且,如果你没有这样的源代码,你可能就不走运了。我认为决定因素是如果((intent.getFlags()&intent.FLAG\u ACTIVITY\u chide\u FRONT)!=intent.FLAG\u ACTIVITY\u chide\u FRONT)
@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();
    }
}