• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Air for Android - how to handle back button?

Community Beginner ,
Jun 16, 2010 Jun 16, 2010

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?

TOPICS
ActionScript

Views

39.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 21, 2010 Sep 21, 2010

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 21, 2010 Dec 21, 2010

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 21, 2010 Dec 21, 2010

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 21, 2010 Dec 21, 2010

Copy link to clipboard

Copied

Thanks Lisa!  It works great.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 28, 2011 Jun 28, 2011

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 28, 2011 Jun 28, 2011

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 11, 2012 Feb 11, 2012

Copy link to clipboard

Copied

LATEST

I wrote a small tutorial on this article here: http://www.grindheadgames.com/handling-button-air-android I hope someone finds it useful.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines