4 Replies Latest reply on Dec 14, 2011 4:32 PM by RevTylerr

    How to close a mobile app.

    RevTylerr

      Hey,

       

       

      I'm testing on Android using AIR. I've got a simple app that uses a flash component that draws with touch inputs.

       

      However, when I use the device's hardware back button, it closes back to the home screen but doesn't actually close anything down. It simply appears to pause it because when I re-open it the drawing is still there... I can use a process manager to force quit it and the stage resets when I open it the next time.

       

      How do I make it close when the back button is pressed?

        • 1. Re: How to close a mobile app.
          frank_aq

          Your container MXML file has an activate and deactivate property, you can use these to handle app open and close.

           

           

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

           

           

           

          You also may want to take a look at sessionCachingEnabled as well as setting the destructionPolicy on your views.

          • 2. Re: How to close a mobile app.
            RevTylerr Level 1

            So, I use the activate or deactivate event handler to manually re-set my flash component?

             

            Is there no way to just shut down app?

            • 4. Re: How to close a mobile app.
              RevTylerr Level 1

              frank_aq wrote:

               

              Your container MXML file has an activate and deactivate property, you can use these to handle app open and close.

               

               

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

               

               

               

              You also may want to take a look at sessionCachingEnabled as well as setting the destructionPolicy on your views.

               

              This actually worked out perfectly.

               

              Once I built more of a flow to my app my original issue ended up not being a problem anymore. Once I pushed and popped my flash component view it refreshed properly. Just so long as I didn't open the app in to it or close out of it.

               

              However, I was having another issue with the app not going back to my launch screen properly. Your solution with deactivate="close(event)" worked fabulously with this issue.

               

              I simply created that event handler close(event) that looks like this:

               

               

                          protected function close(event:Event):void
                          {
                              trace("App Closed");
                              navigator.popAll(null);
                              navigator.pushView(navigator.firstView);
                          }