Skip navigation
Currently Being Moderated

How to quit an Android App - urgent!

Oct 20, 2011 5:27 AM

Tags: #air #app #for #android #button #code #exit

Hi guys,

I'm about to release an Android version of my app. It runs as fast on an Samsung Galaxy S2 - as good as the iPad 2!

 

When you press the home button, the Application stays open in the background and the music plays. It's annoying for the customer to have to manually

go and exit the app from memory.

 

I'm using Air 2.7

 

I found this code online, and put it in the first frame of my timeline, but it get 'syntax errors' on the first 2 lines. Anyone have some code that works?

 

Thanks,

Matt

 

if(Capabilities.cpuArchitecture==”ARM”){

NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true); NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE , handleDeactivate, false, 0, true); NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KE Y_DOWN, handleKeys, false, 0, true);

}

function handleActivate(event:Event):void

{

NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

}

function handleDeactivate(event:Event):void

{

NativeApplication.nativeApplication.exit();

}

function handleKeys(event:KeyboardEvent):void

{

if(event.keyCode == Keyboard.BACK) {

NativeApplication.nativeApplication.exit();

}

}

 
Replies
  • Currently Being Moderated
    Oct 20, 2011 8:22 AM   in reply to monkey500

    Are there any cases where it does quit ok? Like, does pressing the back button work?

     

    I read somewhere about people using and Event.EXITING listener, maybe that would do something.

     

    In any case, throw in a SoundMixer.stopAll() on your deactivate function, and something on your activate function that will take the app back to the main menu, in case you do get stuck with it being open all the time.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2011 8:44 AM   in reply to monkey500

    You do have these import lines, don't you?:

     

         import flash.desktop.NativeApplication;

         import flash.desktop.SystemIdleMode;

         import flash.system.Capabilities;

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2011 9:04 AM   in reply to monkey500

    Make sure the player type is set to either Android or iOS. You would get errors if you have it set to Flash Player.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 4, 2011 6:06 AM   in reply to monkey500

    In the Permissions tab of the Android publishing settings is READ_PHONE_STATE. Check that box. Then when a phone call comes in AIR will automatically mute any sound. That might be enough to keep Amazon happy.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 4, 2011 6:44 AM   in reply to monkey500

    Don't know about the other two boxes you've checked. The Internet one is needed, and the read phone state to get sound muted when a call comes in. Don't know what you're doing that needs the write external storage and wake lock.

     

    Probably doesn't matter anyway, I doubt that Amazon will complain if you have asked for a permission that you end up not actually using. The only thing to note is tha thte user will see the list, and someone somewhere may decline to install the app if you are asking for too many permissions.

     

    Thinking about wake lock, I'm going to check into that one, because maybe that is needed in order to keep the screen alive during long sections of no interactivity. I have an app that might need that permission.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 4, 2011 12:30 PM   in reply to monkey500

    monkey500 wrote:

     

    yes, we don't want to bamboozle the customer with too many - I'm surprised they even have to get asked. I doubt Apple would confuse their customers like that.

     

    Apple actually reviews apps though, Google doesn't.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points