1

As the question suggests I know we can't override the Home key event but if you look into the emulator of android 2.2 you will see an application Car Home it has overridden most of the keys like Home, end call.

Now, the point is how have they done it? I tried to peep into the source code of the app but to my surprise its not available or I am unable to find it, but I don't think later is the case.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81

3 Answers3

9

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.

Aman Alam
  • 11,231
  • 7
  • 46
  • 81
4

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.

YoYoMa
  • 243
  • 1
  • 4
  • 12
Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • I didnt understand can u please describe a little more or some code example how to achieve that link to source code of the app since its open source :) – ingsaurabh Feb 18 '11 at 09:41
  • Look in the manifest for the stock Android launcher and you'll find the answer. – Blrfl Feb 18 '11 at 11:54
1

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>
Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
Dror
  • 2,370
  • 1
  • 18
  • 13
  • I tried this, but if the user sets the app as default launcher the it always starts activity on clicking HOME button. But, the actual behaviour should be that HOME button is overridden only in the app not outside the app. – abhi Jul 17 '14 at 12:14