Reputation: 16780
I'm implementing the onBackPressed() method in my activity. It's crucial to my app that I have this functionality. But, the control never enters this function. It enters onPause() instead, when I press the back button.
But the problem is I can't have the same logic in onPause() because when I call another activity, the current activity calls onPause() and I don't want it to execute what should be in onBackPressed().
Please help.
public void onBackPresed(){
Log.d(TAG,"inside onBackPressed()");
if(STATE == PREVIEW){
}
}
Upvotes: 2
Views: 10751
Reputation: 10738
Just a heads up, the Android developer's blog posted about overriding the back press and dealing with backwards compatibility here.
Upvotes: 3
Reputation: 2942
This is how I do it.
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.d(TAG,"Back key pressed");
return true;
}
return super.onKeyDown(keyCode, event);
}
Upvotes: 5
Reputation: 28665
public void onBackPresed(){
you typed one 's', it should be onBackPressed()
Upvotes: 12