0

How to handle Home Button in device as well as in emulator.

i found these two methode's:-

public void onPause

public void onStop

but according to my needs this in not perfect solution for that. any one guide me.

Community
  • 1
  • 1
Adb
  • 195
  • 1
  • 4
  • 13
  • You can also refer this here, http://stackoverflow.com/questions/3898876/how-to-disable-the-home-key/8889913#8889913 – Andro Selva Jul 09 '12 at 10:44

2 Answers2

1

I found the solution:-

public void onUserLeaveHint()
{
    super.onUserLeaveHint();
}

Only executed when HOME button pressed.

more detail see http://developer.android.com/reference/android/app/Activity.html

Adb
  • 195
  • 1
  • 4
  • 13
0

See, for security reasons android developers itself are not allowing us to change any kind of behaviour wiht home button. But even though if you really want to disable the home button press you can do this by adding below code ....

@Override
public void onAttachedToWindow() {
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    super.onAttachedToWindow();
}

@Override    
public boolean onKeyDown(int keyCode, KeyEvent event) {   

    if(keyCode == KeyEvent.KEYCODE_HOME) {
        Log.i("Home Button","Clicked");
    }


    if(keyCode==KeyEvent.KEYCODE_BACK) {

        finish();
    }

    return false;
}
Daud Arfin
  • 2,499
  • 1
  • 18
  • 37
  • leave the comment for down vote ?? – Daud Arfin Jul 09 '12 at 11:07
  • Sure: 1) You copied the answer already linked in the comments 2) You didn't even read the question, OP said *"I do not want to disable Home button"* upon which you answer *"if you really want to disable the home button"*. This does not answer the question at all. –  Jul 09 '12 at 11:22
  • KEYCODE_HOME will not work see my solution. – Adb Jul 10 '12 at 03:06