0

I think my question is difficult to understand, but here is a simple example to understand what I want

this method above is created by default when generates a new class extend Activity, can display the menu when in click on the Menu Button in android

public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        Log.i("---------------", "----------onCreateOptionsMenu--------------");
        return true;

    }

my purpose is to create a method such onCreateOptionsMenu, but for the Home Button in Android mobile

user2282259
  • 155
  • 1
  • 3
  • 9

2 Answers2

4

The home button cannot be overridden. The only option is to write an custom home launcher.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
rekire
  • 47,260
  • 30
  • 167
  • 264
1

There is no way to intercept the home button on Android, unless you make your app the home screen. This is for security reasons, so that malicious apps cannot take over your device by overriding all the buttons that can exit. The home button is the one sure shot way to be able to leave any app.

If you want to handle the HOME button, implement a home screen.

Override home and back button is case a boolean is true

Check the above link and check the comments also. The approach in the link does not work on ICS.

Useful links

Disable Home Button in Android ICS (4.0)

How can I disable Android 4.0 home button?

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256