Namratha
Namratha

Reputation: 16780

onBackPressed() not being executed

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

Answers (3)

Josh
Josh

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

androidworkz
androidworkz

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

Mathias Conradt
Mathias Conradt

Reputation: 28665

public void onBackPresed(){

you typed one 's', it should be onBackPressed()

Upvotes: 12

Related Questions