Skip to main content
Known Participant
October 20, 2011
Question

How to quit an Android App - urgent!

  • October 20, 2011
  • 1 reply
  • 8624 views

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.KEY_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();

}

}

This topic has been closed for replies.

1 reply

Colin Holgate
Inspiring
October 20, 2011

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.

monkey500Author
Known Participant
October 20, 2011

Actually, none of the code above would publish at all - it threw out errors on the first 2 lines, so I'm not sure what will work. Also, I tried it on my friend's Galaxy SII earlier,

so can't test it right now..

Colin Holgate
Inspiring
October 20, 2011

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

import flash.desktop.NativeApplication;

import flash.desktop.SystemIdleMode;

import flash.system.Capabilities;