-6

I want to do several things if the user press home button,my code does not work.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(keyCode==KeyEvent.KEYCODE_HOME)
    {
        Toast.makeText(this, "Click Home ", Toast.LENGTH_LONG).show();
    }
    return super.onKeyDown(keyCode, event);
}
Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
  • possible duplicate of [Detect home button press in android](http://stackoverflow.com/questions/8881951/detect-home-button-press-in-android) – Sergey Glotov Apr 28 '15 at 23:36

1 Answers1

0

It is impossible to detect the home button press action inside an application. The reason for doing so is to prevent malicious apps that cannot be exited.

Source: Detect home button press in android

Community
  • 1
  • 1
VulfCompressor
  • 1,390
  • 1
  • 11
  • 26