Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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">
Copy link to clipboard
Copied
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();
}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now