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 Anroid 2.0+ a convience method is provided as
-
@Override
-
public void onBackPressed() {
-
-
// implement your override logic here
-
return;
-
}
|
|
Related Links
- How to override back button press in Android?
- Copy Bytes from InputStream to OutputStream - Android
- Programmatically Toggle Function Keys
- How to Capture Screen Shot?
- Capture Screen shot as Image
- How to change Java Application Look and Feel?
- MIDI Sound Player
- Sound Player for .WAV and .AU Files
- Howto programatically move mouse?
- How to get content of Http URL as a String Android?
- mvohra's blog
- Printer-friendly version
- Add new comment
- 2934 reads



How to implement Button OnClickListener in Android?
Did you like this article? Did it Help you Solve your Problem? You can get the all the latest articles published at DeveloperFeed in your email inbox by entering your email address below. Your address will only be used for mailing you the articles, and each one will include a link so you can unsubscribe at any time.


Manpreet is an Architect & Software developer currently focusing on developing mobile apps on the iOS (iPhone/iPad) Platform. He’s the founder of a small iPhone development studio