Reputation: 13588
Can i override the functionality of back
and home
buttons(hardware) in android
? i mean like clicking on home button should go tohome screen of my app
instead of home screen of mobile
Upvotes: 0
Views: 551
Reputation: 13327
Home Buttons:
=> You can't override the behaviour of home button.
Back Buttons:
=> In order to capture or override the default back button press in Android the following onKeyDown method can be implemented by the Activity.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
return true;
}
return super.onKeyDown(keyCode, event);
}
In case of Android 2.0+ a convince method is provided as
@Override
public void onBackPressed() {
// implement your override logic here
return;
}
Upvotes: 3
Reputation: 8242
for back Button Override
public void onBackPressed() {
// implement your override logic here
return;
}
for home key : create a home app . refer : Android Overriding home key
Upvotes: 0
Reputation: 21637
Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_HOME)) {
Intent intent = new Intent(this, Main.class);
startActivity(intent);
return true;
}
return super.onKeyDown(keyCode, event);
}
Upvotes: -1