5 Replies Latest reply on Jul 20, 2011 5:17 AM by Rangora

    Reset App on closure / start up

    s_davies

      I posted this in FB forum but now believe its best here, so my question is :

      I have a android app that I am developing and when I close the app (go to the home screen) then re-open the app its opens within the same page that it was closed.

       

      What I would like is to detect the closing of the app and reset the start page back to the beginning, I have looked but cannot find anything relating to this.

       

      Using Flash Builder 4.5 on a mobile project mainly flex so I can learn flex and not an AS project.

       

      I have used AS to detect if the android phones HOME, MENU and BACK button where pressed and all working but obviously when the home button is pressed it closes

       

      I was hoping to call a function on detecting the home button that woudl pop to the first view before closing thus when opened its looks as if its started again, but nothing, I know these code works as I have a menu pop up on pressing the menu button on the device and trace a message out on the back button.

       

      Am i missing something or is there an easy way to refresh the app / restart it on close ect

       

       

      Many Thanks in advance

      Si

        • 1. Re: Reset App on closure / start up
          blazejewicz Level 4

          Hi,

          if you are already using menu keys you could implement activate/deactivate states behaviors in your application and close it explicitely I think using e.g. solution from that blog:

          http://blogs.adobe.com/flashplatform/2010/10/tip-close-your-android-air-app-on-back-button .html

          ("Tip: Close Your Android AIR App on Back Button"). It gives greater control on application state compared to automatic solutions (like on iOS - where that's not possible to explicitely exit application via NativeApplication.nativeApplication.exit() call.

          (similar solutions based on that blog post are posted on forum already - but that's hard to find them unless using Google's site:forums.adobe.com clause )

          e.g. see: http://forums.adobe.com/message/3399574

           

          hth,

          regards,

          Peter

          • 2. Re: Reset App on closure / start up
            Rangora

            The nativeApplication.exit work on my Ipad 2... Why do you say it's not possible to use it?

             

            What you can do to exit your application when the user deactivate it (if he press the home button) is add an event listener on the NativeApplication for Event.DEACTIVATE.

             

            In your app.mxml (the entry point), add a creationComplete handler and in this handler, add this code :

             

             

            NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, myExiting);

             

            Then create the handler :

             

            public function myExiting(event:Event):void {

                      // this code just return to the view of your choice
                                 navigator.popAll();
                                 navigator.pushView(views.LoginView);


                        // while this code would exit the app
                                NativeApplication.nativeApplication.exit();
                       
                        }

             

            IMPORTANT NOTICE : if you use an external UI api (CameraUI, CameraRoll), the deactivate event will be triggered and your app would be exited. You can find a way to avoid the exiting in this case easily, but don't forget that!!

            • 3. Re: Reset App on closure / start up
              blazejewicz Level 4

              Hi,

              The nativeApplication.exit work on my Ipad 2... Why do you say it's not possible to use it?

              that's OK and it's up to Adobe' what to do with that fact as on iOS exit is strongly not recommended, see:

              http://developer.apple.com/library/ios/#qa/qa1561/_index.html

              As I recall most posts here on forum discourage using exit on iOS and people not use it, see e.g. words from Adobe's employe here:

              iOS does not provide a way to exit the application. So it is expected that nativeApplication.exit() won't work on iOS and it does on Android.

              http://forums.adobe.com/thread/870733

              So I'd write test case for Adobe and upload for their consideration what to do,

              Notice that "not recommended" behaviors by Apple are subject of AppStore rejections I believe.

              regards,

              Peter

              • 4. Re: Reset App on closure / start up
                s_davies Level 1

                Thanks fpr the replies, I am off work thi sweek and my test devices are at work so cannot check on devices to test properly but can on the emulators at home.

                Will get back to this and reply properly once tested on an actual device

                 

                Si

                • 5. Re: Reset App on closure / start up
                  Rangora Level 3

                  Thx for the info.

                   

                  It's not a problem in my case since it will be use with an enterprise license and won't be in the app store.

                   

                  If you can't exit on iOS, I would suggest to use the first part of my method (with the popAll push)