14 Replies Latest reply: Nov 4, 2011 12:30 PM by Idlemedia RSS

    How to quit an Android App - urgent!

    monkey500 Community Member

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

      }

      }

        • 1. Re: How to quit an Android App - urgent!
          Colin Holgate CommunityMVP

          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.

          • 2. Re: How to quit an Android App - urgent!
            monkey500 Community Member

            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..

            • 3. Re: How to quit an Android App - urgent!
              Colin Holgate CommunityMVP

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

               

                   import flash.desktop.NativeApplication;

                   import flash.desktop.SystemIdleMode;

                   import flash.system.Capabilities;

              • 4. Re: How to quit an Android App - urgent!
                monkey500 Community Member

                That must be it - I didn't have any code for Android yet.  Thanks, I'll get my friend to test it with the above code

                • 5. Re: How to quit an Android App - urgent!
                  monkey500 Community Member

                  It's still getting 2 syntax errors on this line when I publish a swf:

                   

                  if(Capabilities.cpuArchitecture==”ARM”){

                  • 6. Re: How to quit an Android App - urgent!
                    Colin Holgate CommunityMVP

                    Make sure the player type is set to either Android or iOS. You would get errors if you have it set to Flash Player.

                    • 7. Re: How to quit an Android App - urgent!
                      monkey500 Community Member

                      Yes, it's set to Android.

                       

                      It's the 'Arm' line that's always having the prob. Any all the code I find uses this line..

                       

                      I found another link:

                      http://cartoonsmartblog.wordpress.com/2011/04/04/what-to-do-when-your-air-to-android-app-c loses/

                       

                      He says this too:

                       

                      "One thing to note too, posting your app to the Google Android Market store is like the wild west of app stores. Anything goes. The app will be live within minutes and there’s no review from Google prior to posting. So they don’t really care if you handle closing/pausing your app correctly. BUT I submitted one of my games to Amazon App Store and they were more particular about what the app did in the background. Basically they didn’t want it to just quit entirely if a phone call interrupted the game. And I submitted this game months before I knew any better so at the time, my code for handling the Home or Back buttons just quit out the app entirely. They didn’t like that. So Amazon rejected it for not pausing on deactivation."

                      • 8. Re: How to quit an Android App - urgent!
                        monkey500 Community Member

                        Hi guys, my Android app was rejected by Amazon for the reasons below. (needs to pause on incoming call)

                         

                        I've still not had any code that actually publishes my Android File, so if anyone has experience of what works, please post here, including the Android classes I'd need on my first frame.

                         

                        If i'm using Flash CS5.5 with Air 2.7, so I need to install the Android SDK or not?

                         

                        Thanks!

                        Matt

                         

                         

                        Amazon's message:

                         

                        "Your app has failed a test case. Bug Description:An incoming voice call does not place the application in a pause state. When the interrupt is received, the audio generated by the application continues to play and is audible for the duration of the voice call. Steps to Reproduce: 1) Launch the application 2) Initiate a voice interrupt 3) Observe that, when the interrupt is initiated on the test device, the audio generated by the application continues to play 4) Accept the interrupt 5) Observe that the audio generated by the application continues to play for the duration of the interrupt OS/Device(s)/Form Factor: HTC Sensation 4G A 1.03.531.1 "

                         

                        Please correct the issue(s) we found with your app submission so we may continue working to get it in the Appstore.

                        • 9. Re: How to quit an Android App - urgent!
                          Colin Holgate CommunityMVP

                          In the Permissions tab of the Android publishing settings is READ_PHONE_STATE. Check that box. Then when a phone call comes in AIR will automatically mute any sound. That might be enough to keep Amazon happy.

                          • 10. Re: How to quit an Android App - urgent!
                            monkey500 Community Member

                            Thanks Colin, that's a handy toggle - I'll try resubmitting it!

                            • 11. Re: How to quit an Android App - urgent!
                              monkey500 Community Member

                              Right, just found the culprit for the above code - the syntax for the code I'd found had changed the punctuation.

                               

                              I've ticked these boxes in the permissions. They seemed like the right thing to do, but let me know if I should

                              untick any of them!

                               

                              - INTERNET

                              - WRITE EXTERNAL STORAGE

                              - READ PHONE STATE

                              - WAKE LOCK

                               

                              This code has now been corrected, and does publish, but I haven't tested it yet:

                               

                               

                               

                              import flash.desktop.NativeApplication;

                               

                              import flash.desktop.SystemIdleMode;

                               

                              import flash.system.Capabilities;

                               

                              import flash.system.System;

                               

                                  

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

                               

                                  }

                               

                                  }

                              • 12. Re: How to quit an Android App - urgent!
                                Colin Holgate CommunityMVP

                                Don't know about the other two boxes you've checked. The Internet one is needed, and the read phone state to get sound muted when a call comes in. Don't know what you're doing that needs the write external storage and wake lock.

                                 

                                Probably doesn't matter anyway, I doubt that Amazon will complain if you have asked for a permission that you end up not actually using. The only thing to note is tha thte user will see the list, and someone somewhere may decline to install the app if you are asking for too many permissions.

                                 

                                Thinking about wake lock, I'm going to check into that one, because maybe that is needed in order to keep the screen alive during long sections of no interactivity. I have an app that might need that permission.

                                • 13. Re: How to quit an Android App - urgent!
                                  monkey500 Community Member

                                  yes, we don't want to bamboozle the customer with too many - I'm surprised they even have to get asked. I doubt Apple would confuse their customers like that.

                                   

                                  I thought the Write External Storage should be essential for Google market, if they're phones with a tiny memory. I expect that will run out if they download a lot..

                                  • 14. Re: How to quit an Android App - urgent!
                                    Idlemedia Community Member

                                    monkey500 wrote:

                                     

                                    yes, we don't want to bamboozle the customer with too many - I'm surprised they even have to get asked. I doubt Apple would confuse their customers like that.

                                     

                                    Apple actually reviews apps though, Google doesn't.