tags:

views:

55

answers:

1

Hi,

I was trying to override the back button functionality where I wanted to call the default functionality in case a boolean is set false

public boolean onKeyDown(int keyCode, KeyEvent event) {
        boolean temp = false;
        if (event.KEYCODE_BACK == keyCode) {
            System.out.println("Back pressed");
            if (isTrue) {
                //Do something
                return true;
            }
            else return false;
        }
        return false;
    }

Now this doesn't exactly work how the documentation states. the //Do Something part is executed well, but when isTrue is false i want the default back functionality which is not happening. Im using SDK 1.5

Now,

  1. How do I fix this?

  2. Is this issue fixed in later SDK updates? If not can someone raise a bug for the same?

+3  A: 
  1. If you want the default behavior, chain to the superclass:

    return(super.onKeyDown(keyCode, event));

  2. The bug is in your code. Also, for Android 1.6 and newer, you are better served overriding the dedicated onBackPressed() method (where, again, if you want the default behavior, chain to the superclass).

CommonsWare
Also, you should consider reading this: http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
Samuh
Thanks commonsware. I was actually following the documentation as is and it mentioned returning false would work. Also thanks ( to Samuh as well) for pointing out the changes for vr1.6 but as per the requirements I have to stick with vr1.5 for now.
Funkyidol
I can see where you might interpret it that way -- it's not written terribly well -- but the documentation does not say what you think it does.
CommonsWare