logo
Login

Sponsored Links

Sponsored

How to override back button press in Android?

In order to capture or override the default back button press in Android the following onKeyDown method can be implemented by the Activity.

  1. @Override
  2. public boolean onKeyDown(int keyCode, KeyEvent event) {
  3.     if (keyCode == KeyEvent.KEYCODE_BACK) {
  4.         moveTaskToBack(true);
  5.         return true;
  6.     }
  7.     return super.onKeyDown(keyCode, event);
  8. }

In case of Anroid 2.0+ a convience method is provided as

  1. @Override
  2. public void onBackPressed() {
  3.  
  4.     // implement your override logic here
  5.    return;
  6. }

Like Developerfeed? Follows us via: RSS Feed Follow me on Twitter! Follow me on Facebook! Follow me on Youtube!

Socialize & Share Now :

Subscribe to DeveloperFeedDid 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.

Enter your email address:

Subscribe & Follow

RSS Feed Follow me on Twitter! Follow me on Facebook! Follow me on Youtube!
Feed via Email:

Sponsored Links

Facebook

Sponsored Apps

Job Change Alert for Linkedin


Contact2CRM for Salesforce


Advertise on DeveloperFeed

About

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
called Livrona.

Subscribe to Developer Feed iPhone Blog

Tags

Who's online

There are currently 0 users and 5 guests online.