Android Overriding home key

我与影子孤独终老i 提交于 2019-11-26 15:31:48

I agree with @Romain Guy

You can't override the behaviour of home button.

What the Car Home app does: it has defined itself as a launcher. You can also define yours as a launcher, and it will be notified when the home screen is about to be launched.

Check this out : Intent.html#CATEGORY_LAUNCHER

Please note that this doesn't mean that your app/activity is notified when the home button is pressed so that it can override the behaviour of it, but is notified when the system is about to launch the Home Screen. Both are different things. in this type of notification, Android already has sent the app (Which is currently executing) to the frozen state, and it won't have any control over what's happening.

This is as far as I know. I guess @Romain Guy may correct me if I am wrong at any place.

Romain Guy

It does not override the Home key, the Car Home application just behaves as a launcher, which any application can do. This behavior gets declared in the manifest file.

Dror

Looks like the following does it on 4.0:

In AndroidManifest.xml

<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.HOME"/>
    <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!