Copy link to clipboard
Copied
I have two questions:
1. Where is the Adobe Air for Android (or Flash for Android) or Adobe sanctioned mobile development forum?
2. I am developing a Flash/AS3 app for Android. How can I handle the back button to go back within my own application when appropriate?
Copy link to clipboard
Copied
1) You can register for Pre Release programm (https://prerelease.adobe.com/) and get the AIR SDK for the Android.
2) The Back, Menu, Search button works with Keyboard Event. You can add the Key Event to the stage and Check the keyCode with the Keyboard class constance like, Keyboard.BACK, Keyboard.MENU, Keyboard.SEARCH.
I hope this answers your question.
Copy link to clipboard
Copied
My code is working insofar as the menu button gets captured as well as the back button.. but I can only see my back button is function right before it goes to the previous application running on my nexus 1. I even added the uses permission FORCE_BACK. Please advise if this is possible or reliable on a range of devices. Thanks!
Copy link to clipboard
Copied
Hi Phillip,
You need to call preventDefault() and stopImmediatePropagation() on the KeyboardEvent.
Here is my code:
function onKeyPress(ev:KeyboardEvent):void
{
switch(ev.keyCode)
{
case Keyboard.BACK: // user hit the back button on Android device
// case 94: // was hard-coded for older build of SDK supporting eclair
{
if(null != _currentScreen)
{
// TO DO - make this smarter?
if(_currentScreen.goBack())
{
// don't let the OS kill focus to our app
ev.preventDefault();
ev.stopImmediatePropagation();
}
}
break;
}
}
- Lisa
Copy link to clipboard
Copied
Thanks Lisa! It works great.
Copy link to clipboard
Copied
I am not getting the default behavior to be overriden -- I am trying to prevent the back button from popping the view by default (I have a Samsung Charge, FB 4.5, Windows). It gets into the key handler, but the instructions appear to be ignored:
protected function onKeyDown (event:KeyboardEvent):void {
event.preventDefault();
event.stopImmediatePropagation();
}
and I registered the listener with priority 0 (even tried true and false for useCapture, to see if for some reason it was the listener order), but it's still doing the default behavior of popping the view.
Any thoughts about why this is not working?
Copy link to clipboard
Copied
I figured it out, though I don't know why the key handler was not working.
The View class has an event "backKeyPressed", so I can put the preventDefault() and stop propagation there. I don't need all the key listener stuff and such.
Copy link to clipboard
Copied
I wrote a small tutorial on this article here: http://www.grindheadgames.com/handling-button-air-android I hope someone finds it useful.