6 Replies Latest reply: Nov 25, 2012 7:16 AM by kglad RSS

    Reset app on exit

    soremite Community Member

      How do I have my app automatically reset on exit. I can do it when someone presses an exit button, but on mobile phones people just press the home button and the app saves state.

       

      I want to reset a concentration style game since it is timed and wouldn't be fair to pause the game and come back later.

       

      Thanks.

        • 1. Re: Reset app on exit
          kglad MVP

          the NativeApplication class has an Event.USER_IDLE event you can use to detect when (and for how long using Event.USER_PRESENT) your app has been idled.

           

          and, you can prevent idle mode (on some systems) by using NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

           

          in any case, check the NativeApplication class for all sorts of things you can do to control how your app behaves and is behaving when it's running.

          • 2. Re: Reset app on exit
            soremite Community Member

            I have used these lines:

             

            application.addEventListener(Event.DEACTIVATE, deactivate);

             

            application.addEventListener(Event.EXITING, exiting);

             

            private function exiting(e:Event):void

            {

                textBox.text = "Shake!";

                application.removeEventListener(Event.ACTIVATE, activate);

                application.removeEventListener(Event.DEACTIVATE, deactivate);

                application.removeEventListener(Event.EXITING, exiting);

                application.systemIdleMode = SystemIdleMode.NORMAL;

             

            }

             

             

            But it doesn't put the words back in the text box.

            • 3. Re: Reset app on exit
              kglad MVP

              where is application defined?  (and, unless it's defined as NativeApplication.nativeApplication, it's wrong.)

              • 4. Re: Reset app on exit
                soremite Community Member

                function Main()

                {

                    application = NativeApplication.nativeApplication;

                    application.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

                    application.addEventListener(Event.ACTIVATE, activate);

                    application.addEventListener(Event.DEACTIVATE, deactivate);

                }

                • 5. Re: Reset app on exit
                  soremite Community Member

                  I've made some progress using Event.activate as well as Event.exiting.

                  • 6. Re: Reset app on exit
                    kglad MVP

                    great.

                     

                    please mark helpful/correct responses.