Possible Duplicate:
is there a default back key(on device) listener in android?
How can I respond to the physical back button in my Android application? Like a listener of a sort.
I want to do things when that button is pressed!
Possible Duplicate:
is there a default back key(on device) listener in android?
How can I respond to the physical back button in my Android application? Like a listener of a sort.
I want to do things when that button is pressed!
If I understand your question, simply override onBackPressed()
in your Activity for API 5+.
@Override
public void onBackPressed() {
super.onBackPressed();
// Do something
}
You can use the following code:
@Override
public boolean onKeyDown( int keyCode, KeyEvent event ) {
if ( keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 ) {
// do something on back.
return true;
}
return super.onKeyDown( keyCode, event );
}
You can find more information on the Android Developer's Blog.