Android启动preSS家在发射进入默认屏幕 [英] Android launcher press home in launcher to go to default screen

查看:268
本文介绍了Android启动preSS家在发射进入默认屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在默认的Andr​​oid启动,pressing家,而在另一个活动将开始启动。 pressing回家了,而在发射器将重置为默认主屏幕页面。我不知道如何可以做到这一点。机器人发送相同的意图启动器是否在前台或没有。 Home键也无法由用户的应用程序被截获。

有没有办法来实现这一目标?


解决方案

  

Android的发送相同的意图发射器是否在前台与否。


正确的。


  

Home键也无法由用户的应用程序被截获。


正确的。


  

我不知道如何可以做到这一点。


如果一个呼叫 startActivity()将导致意图被传递到活动的现有实例,则不会创建一个新的实例(定义)和现有实例被称为与 onNewIntent()而不是的onCreate()

在主屏幕,一般的活动,真正的的主屏幕将使用的android的情况:launchMode =singleTask的android:在launchMode =singleInstance清单,如:

 <活动
        机器人:名字=启动器
        机器人:launchMode =singleTask
        机器人:clearTaskOnLaunch =真
        机器人:stateNotNeeded =真
        机器人:主题=@风格/主题
        机器人:screenOrientation =nosensor
        机器人:windowSoftInputMode =stateUnspecified | adjustPan>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.HOME/>
            <类机器人:名字=android.intent.category.DEFAULT/>
            <类机器人:名字=android.intent.category.MONKEY/>
        &所述; /意图滤光器>
    < /活性GT;

(从在AOSP 老发射器)

然后,该活动可以实现 onNewIntent()做一些事情。在上述旧发射器的情况下,<一href=\"https://github.com/android/platform_packages_apps_launcher/blob/master/src/com/android/launcher/Launcher.java\">its onNewIntent()包括:

 如果(!mWorkspace.isDefaultScreenShowing()){
                mWorkspace.moveToDefaultScreen();
            }

本,presumably,动画用户界面返回到默认屏幕如果用户是presently查看该组由主屏幕活动管理屏幕内的一些其它屏幕。

另一种方法来触发 onNewIntent(),而不是使用的android:launchMode ,是做选择的时候你叫 startActivity(),通过在适当参数的意图,如 FLAG_ACTIVITY_REORDER_TO_FRONT

In the default android launcher, pressing home while in another activity will start the launcher. Pressing home again while in the launcher will reset to the default home screen page. I don't understand how this can be done. Android sends the same intent whether the launcher is in the foreground or not. Home key also cannot be intercepted by user apps.

Is there a way to achieve this?

解决方案

Android sends the same intent whether the launcher is in the foreground or not.

Correct.

Home key also cannot be intercepted by user apps.

Correct.

I don't understand how this can be done.

If a call to startActivity() will result in the Intent being delivered to an existing instance of the activity, a new instance is not created (by definition) and the existing instance is called with onNewIntent() instead of onCreate().

In the case of a home screen, typically the activity that truly is the home screen will use android:launchMode="singleTask" or android:launchMode="singleInstance" in the manifest, such as:

    <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>

(from an old launcher in the AOSP)

Then, the activity can implement onNewIntent() to do something. In the case of the aforementioned old launcher, its onNewIntent() includes:

            if (!mWorkspace.isDefaultScreenShowing()) {
                mWorkspace.moveToDefaultScreen();
            }

This, presumably, animates the UI back to the default screen if the user is presently viewing some other screen within the set of screens managed by the home screen activity.

Another approach to trigger onNewIntent(), instead of using android:launchMode, is to do it selectively when you call startActivity(), by including appropriate flags in the Intent, such as FLAG_ACTIVITY_REORDER_TO_FRONT.

这篇关于Android启动preSS家在发射进入默认屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆