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

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

Explorer ,
Dec 09, 2011 Dec 09, 2011

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.

TOPICS
Development
10.0K
Translate
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
Explorer ,
Dec 09, 2011 Dec 09, 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">


Translate
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
Explorer ,
Dec 09, 2011 Dec 09, 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();

    }

}

Translate
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
Engaged ,
Dec 09, 2011 Dec 09, 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

Translate
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 09, 2011 Dec 09, 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

Translate
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
Engaged ,
Dec 09, 2011 Dec 09, 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/

Translate
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 10, 2011 Dec 10, 2011

Thanks a lot for that,

I'll try to code it myself, and will just pause the music. I've found Sound in AS3 to be a real pain. But have got the hang of it thanks to Republic of code's great tutorials!

Translate
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 ,
Oct 07, 2012 Oct 07, 2012

Hi everyone, i have made a little sound player but i got some issues:

> - The game got 3 frames: Home - Play - Score

Home  = The app start, sound start playing

Play  = Play the game

Score = Show score and best score

If i go to home (first frame) the music play over himself (start a new instance without stoping the first one)

If i exit, the application still's playing the music (phone call or home button on phone)

Sound Linkage: imported to library and made a linkage to AS3

I just want that: app start, music start playing infinite and when i exit i want to stop or close the sound/app

Any help will be really appreciated

Flash CS6 - AIR 3.4 Android and iOS

<code>

//play sound

var musicplayed:int = 0;

var musicPlayer:Sound = new MyMusic();

var songChannel:SoundChannel;

songChannel = musicPlayer.play();

function loopMusic(event:Event)

{

    songChannel = musicPlayer.play();

    songChannel.addEventListener(Event.SOUND_COMPLETE, loopMusic);

}

//stop sound

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

function handleDeactivate(event:Event):void {

      //the app is now losing focus

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

}

//resume sound

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

function handleActivate(event:Event):void {

    songChannel= musicPlayer.play();

}

</code>

Translate
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
LEGEND ,
Oct 07, 2012 Oct 07, 2012

If the script for playing the music is in the same frame as Home, then it would start another one playing. Try having that script in a frame earlier than the Home frame.

Translate
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 ,
Oct 07, 2012 Oct 07, 2012
LATEST

Mr. Colin thanks for reply me, i have made that but every time i travel through the frames (Home Play Score) the event Play(); is fired, so is easy to get 10 instances of the music playing at same time

Just a little thing, i'm ready to drop all that code and adopt another solution to:

Play the background music (loop)

Stop/Pause/Resume/Exit App when loose the focus (phone call/screen sleep (avoid resume app on lock screen ))

Many thanks in advance, mate;

Translate
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