6

I have been searching through Android docs and stackoverflow and most of the answers I am reading say that you cannot disable or override the Android home button.

Tried - does not work

Says not possible

The problem is there are known apps that are doing this:

Kids Care

Kids Place

This is what I want:

A parent loads the app then gives device to a child. The child can only see the approved apps that are on the device (I know how to do this part). If they load an approved app from the main launcher screen on my app - if they press the home button, it takes them back to my app and not back to the device home screen. If a user presses the home button from my app - nothing should happen. Same goes for the back button.

I am looking for the proper solution in duplicating functionality of Kids Care app in overriding home button. How do I do it?

Community
  • 1
  • 1
Spentak
  • 3,359
  • 3
  • 21
  • 31
  • This is an interesting question, from a usability built of view this sounds like a bad idea and could frustrate many users. Best of luck finding the answer you're after – mdoran3844 Sep 12 '13 at 23:37

4 Answers4

2

If anyone is still interested, you could try putting this in your main activity in AndroidManifest.xml

<activity
    ...
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />
        ....
    </intent-filter>
</activity>
klifa
  • 671
  • 1
  • 8
  • 27
1

What you need to do is create your own launcher which either A) Starts another launcher or B) starts your activity. The launcher just has to be smart enough to know which to launch. So if you're in your app and you click "home" it will get into the launcher code and see that your app is running and decide to start your activity. However it it decides your app isn't running then it should start another launcher. If you remove the activity animations then it will appear seamless.

Randy
  • 4,351
  • 2
  • 25
  • 46
  • There really isn't any need for example code. It's a simple activity with the launcher flag in the manifest. Then in the `onStart` event decide what other app to run (Your activity vs another activity). – Randy Dec 12 '13 at 21:54
0

In activity override the method

  @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
                case android.R.id.home:
                    onBackPressed();
                    break;
                default:
                    return super.onOptionsItemSelected(item);
            }
            return false;
        }
Diana S.
  • 51
  • 1
  • 3
-2

Never overrode home button, but this works for me overriding back button.-

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean res = super.onKeyDown(keyCode, event);

    switch (keyCode) {
    case KeyEvent.KEYCODE_HOME: {
        // Your Home button logic;
        return false;
    }

    return res;
}

Hope it helps.

ssantos
  • 16,001
  • 7
  • 50
  • 70