1

Is that possible to get notification when Home button is pressed or Home Screen is launched?

In Android Overriding home key thread i read that "it will be notified when the home screen is about to be launched". So is that possible, if yes how?

Thank you

Community
  • 1
  • 1
MaheshValu
  • 101
  • 2
  • 10

3 Answers3

1

Is that possible to get notification when Home button is pressed or Home Screen is launched?

Only by being a home screen.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I tried it by making home screen but when i press home button it asked me to select one of available Home Screens. – MaheshValu Oct 14 '11 at 06:32
  • @user992888: That is expected behavior. The user gets their choice of home screens -- you do not get to dictate terms to the users. – CommonsWare Oct 14 '11 at 11:06
0

You can Detect Home Screen is running or not.
You can see this page for more details,Or you can see this answer.It propose use isScreenOn () from PowerManager(Returns whether the screen is currently on. The screen could be bright or dim):

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
Community
  • 1
  • 1
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
0

You can simply add this on your activity:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_HOME) {
        // Do something
    }

    return super.onKeyDown(keyCode, event);
}
Draiken
  • 3,805
  • 2
  • 30
  • 48
  • @user992888 what does that response mean? If it worked accept the answer if not give more detail – Moog Oct 13 '11 at 22:44
  • `Is that possible to get notification when Home button is pressed or Home Screen is launched?` the code DOES notify you that the home button is pressed, what does `This want to work...` means? I answered what you asked. – Draiken Oct 14 '11 at 19:17