首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android launcher在launcher中按home键进入默认屏幕

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

Stack Overflow用户
提问于 2012-11-03 05:52:27
回答 2查看 6K关注 0票数 4

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

有没有办法做到这一点?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-03 06:21:37

无论launcher是否在前台,

Android都会发送相同的意图。

对,是这样。

主页密钥也不能被用户应用程序拦截。

对,是这样。

我不明白怎么能做到这一点。

如果对startActivity()的调用将导致Intent被传递到该活动的现有实例,则不会创建新实例(根据定义),并且使用onNewIntent()而不是onCreate()调用现有实例。

在主屏幕的情况下,通常是主屏幕的活动将在清单中使用android:launchMode="singleTask"android:launchMode="singleInstance",例如:

代码语言:javascript
复制
    <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

代码语言:javascript
复制
            if (!mWorkspace.isDefaultScreenShowing()) {
                mWorkspace.moveToDefaultScreen();
            }

如果用户当前正在观看由主屏幕活动管理的屏幕集合中的某个其他屏幕,则这大概使UI动画回到默认屏幕。

触发onNewIntent()的另一种方法不是使用android:launchMode,而是在调用startActivity()时有选择地执行,方法是在Intent中包含适当的标志,如FLAG_ACTIVITY_REORDER_TO_FRONT

票数 12
EN

Stack Overflow用户

发布于 2014-02-16 12:58:26

更具体地说,请执行以下操作

代码语言:javascript
复制
@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();
    }
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13203536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档