1 Reply Latest reply on Feb 16, 2011 3:21 AM by FlashKevin

    Android App won't start 2nd time if play sound


      Hi, my problem is simply this. When testing on mobile device (Samsung Galaxy S) my Android App will not launch a second time. I've narrowed this down to whether or not I play a sound. On first run the sound plays and app exits when you press the back button. You cannot see the app in the task manager. However the app will not run a 2nd time. I'm working in Flash CS5 using the Air2.5 Android extension.

      private var sndMusic:Sound;
      private var sndChannel:SoundChannel;

      sndMusic = new Music1();
      sndChannel = sndMusic.play();        // if this line is included APP fails on second launch


      I made a stencil action script file which just plays a sound to demonstrate this. Any ideas?


          import flash.display.Sprite;
          import flash.events.Event;
          import flash.events.KeyboardEvent;
          import flash.ui.Keyboard;
          import flash.desktop.NativeApplication;
          import flash.desktop.SystemIdleMode;
          import flash.display.StageScaleMode;
          import flash.display.StageAlign;
          import flash.system.Capabilities;
          import flash.media.Sound;
          import flash.media.SoundChannel;
          import flash.media.SoundMixer;
          import flash.display.Graphics;
          import flash.display.NativeWindow;
          import assets.Music1;          // import from SWC file
          [SWF(width="480", height="800", backgroundColor="#000000", frameRate="25")]
          public class AudioTest extends Sprite
              private var sndMusic:Sound;
              private var sndChannel:SoundChannel;


              public function AudioTest()
                  trace("------------------------ AudioTest()");
                      trace("added system event listeners");
                      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);
                      NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExit);
                  this.stage.scaleMode = StageScaleMode.NO_SCALE;
                  this.stage.align = StageAlign.TOP_LEFT;
                  stage.stageFocusRect = false;
                  this.graphics.drawRect(0,0, 100,100);
                  sndMusic = new Music1();
                  sndChannel = sndMusic.play();        // if this line is included APP fails on second launch
              function handleActivate(event:Event):void {
                  NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
              function handleDeactivate(event:Event):void {
                  trace("-------------------- AudioTest() deactivate");
                  // NativeApplication.nativeApplication.exit();
              private function onExit(exitingEvent:Event):void {
                  trace("-------------------- AudioTest() onExit()");
                  trace("-------------------- AudioTest() SoundMixer.stopAll()");
                  sndChannel = null;
                  sndMusic = null;
                  trace("-------------------- values set to null");
                  var winClosingEvent:Event;
                  for each (var win:NativeWindow in NativeApplication.nativeApplication.openedWindows) {
                      winClosingEvent = new Event(Event.CLOSING,false,true);
                      if (!winClosingEvent.isDefaultPrevented()) {
                      } else {
                  if (!exitingEvent.isDefaultPrevented()) {
                      //perform cleanup
              function handleKeys(event:KeyboardEvent):void {
                  if(event.keyCode == Keyboard.BACK) {
                      trace("-------------------- AudioTest() exiting");
                      var exitingEvent:Event = new Event(Event.EXITING, false, true);
                      if (!exitingEvent.isDefaultPrevented()) {
                          trace("-------------------- AudioTest() can exit");