0

I am developing an android application. There is first login page and after that pages as per requirement. when i pressed button home button it comes out on android main screen. and when i starts application again it moves on Activity it left previously instead of moving on login page. please help me out. how can i achieve this?

Nitesh Kabra
  • 71
  • 2
  • 4
  • 11

2 Answers2

1

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

@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;
}
Community
  • 1
  • 1
Daud Arfin
  • 2,499
  • 1
  • 18
  • 37
  • 1
    I added attribution for where you drew the above code from. In the future, please do give credit to the sources that you draw your answers from. – Brad Larson Jul 13 '12 at 16:24
0

Try to override onUserLeaveHint to catch event:

onUserLeaveHint() Called as part of the activity lifecycle when an activity is about to go into the background as the result of user choice.

(http://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint())

Alex Kucherenko
  • 20,168
  • 2
  • 26
  • 33