Skip to main content
Inspiring
December 9, 2011
Question

Urgent! Need to know how to turn off Android app when multitasking/exiting the app.

  • December 9, 2011
  • 2 replies
  • 10015 views

I have two apps in the market (won't reveal name atm) and gets tons of complaints from people about the apps still running, playing music etc when they jump out of the app. It was no problem for myself as I always proper quit all apps I don't use, but most people doesn't seem to do this.

PLEASE, is there any way to shut down the android app or at least PAUSE it, like it does on iOS?

No Flex, Flash Builder solutions please, I use Flash CS 5.5.

This topic has been closed for replies.

2 replies

Inspiring
December 9, 2011

depending on what your app does, you might want to just stop the audio. In a game i wrote, if a deactivate event occurs (example: a phone call) it would be anoying for the app to exit and loose the possition in the game. I chose to stop all audio and call my pause/game menu function.

Just another option.

I agree though about closing apps, i always try to exit properly, and my personal opinion is that allapps should have an option to exit... they usually dont though

Known Participant
December 10, 2011

Boat5 - could you please post any code that you used to pause the sound? I can't believe adobe still doesn't have a solution for this. My app kept getting rejected by Amazon because of the call interrupt problem.. Is there was a global pause sound function? In the permissions setting, the read phone state option still didn't work for Amazon..

Thanks,

Matt

Inspiring
December 10, 2011

Event.DEACTIVATE is called when the app looses focus (phone call or press home button), and Event.ACTIVATE is called with the app regains focus.

So in TenchyMyos code above, just adjust the sound in the handleDeactivate function.

For example if you have music playing in a sound channel:

NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE , handleDeactivate, false, 0, true);

function handleDeactivate(event:Event):void {

      //the app is now losing focus

      musicChannel.stop(); // stops the music, assuming "musicChannel" is a SoundChannel assigned to play your music

}

Or if you want to universally stop all sounds you can use the stopAll() method in the SoundMixer class

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundMixer.html

On reactivate you might want to start the music again... or whatever

NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);

function handleActivate(event:Event):void {

    musicChannel= mySong.play();

}

some instructions to save the position of the playhead while your "pausing" for deactivation... AKA just stopping and restarting the sounds on focus changing events

http://www.republicofcode.com/tutorials/flash/as3sound/

TenchyMyoAuthor
Inspiring
December 9, 2011

I've found this one and tried it, but it quits the app immedately after it has been started, which I don't want:

NativeApplication.nativeApplication.exit();

Then this one:

var exitingEvent:Event = new Event(Event.EXITING, false, true);
NativeApplication.nativeApplication.dispatchEvent(exitingEvent);
if (!exitingEvent.isDefaultPrevented()) {
NativeApplication.nativeApplication.exit();
}

Which should check for some type of exiting even and THEN trigger the "NativeApplication.nativeApplication.exit()", but also that method instantly quits the apps when it's started.

Then I found this one, but it's not Flash, prolly native Android code or Flex or something, so can't test it:

<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                            xmlns:s="library://ns.adobe.com/flex/spark"
                            activate="open(event)" deactivate="close(event)" firstView="views.Home">


TenchyMyoAuthor
Inspiring
December 9, 2011

Yay, solution found!

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

    }

}