PDA

View Full Version : Android back button



karelc
07-26-2011, 01:33 PM
Is there any other way to use the physical back button beside connecting it to an onscreen button?
And is there any way to enable the button in other activities? I can switch between proton and android activities in the same app, but the back button doesn't work in the android activities. I presume you disabled it to prevent it quitting proton apps outright, but I need it enabled here as this part of my app works like android was designed.

Seth
07-26-2011, 01:49 PM
The back button triggers BaseApp::m_sig_input() with a parm1 value of VIRTUAL_KEY_BACK.

I do signal on the Java side that "we handled it" - this may be causing you problems..

SharedActivity.java does it this way (and similar for onKeyUp as well)

(look at the case KeyEvent.KEYCODE_BACK, that's where it is..)


public boolean onKeyDown(int keycode, KeyEvent e)
{
// Log.v("onKeyDown","Keydown Got "+keycode+" "+Character.toString(Character.toChars(e.getUnicode Char())[0]));


if (e.getRepeatCount() > 0) return super.onKeyDown(keycode, e);


switch (keycode)
{
case KeyEvent.KEYCODE_BACK:
{
//Log.v("onKeyDown","Sending virtual back");
nativeOnKey(1, VIRTUAL_KEY_BACK, e.getUnicodeChar());
return true; //signal that we handled it
}
}

int vKey = TranslateKeycodeToProtonVirtualKey(keycode);
nativeOnKey(1, vKey,e.getUnicodeChar()); //1 means keydown
return super.onKeyDown(keycode, e);
}

So perhaps instead of

return true; //signal that we handled it

you need:

return super.onKeyDown(keycode, e);

?

If you can verify that fixes it, I could add a way to turn on that behavior on/off or something so you don't have to maintain your own version of SharedActivity.java for it.

Seth
07-26-2011, 01:51 PM
Is there any other way to use the physical back button beside connecting it to an onscreen button?

Oh, to answer this - yes, it doesn't need to be connected to an actual button, the RTBareBones example connects to it a function. (OnExitApp or something)

karelc
07-27-2011, 04:29 PM
Apparently the back button is also connected to a function in all of the mainmenu examples, I don't know how I missed that until now. But it's not exactly working right if I use it in other screens. It calls the function I assigned which quits to the previous screen (currently basically a copy of mainmenu from one of the examples) but the button instantly activates the function that back is connected to there as well, quitting the app. With AddHotKeyToButton, that doesn't happen.

And yes, with those changes (just disabling what you had, only keeping the last line) using the back button in another activity works as android was designed, ie it stops and goes back to the previous activity.