Packagecom.wadedwalker.nativeExtension.app
Classpublic final class AppActivityState
InheritanceAppActivityState Inheritance flash.events.EventDispatcher

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The AppActivityState class provides the means of detecting the application state and know when it changes. The main attractors for this is being able to save app data on pause or quit and restore the app data when it resumes or is relaunched from a closed state.

To use this native extension, simply create an instance of the AppActivityState class, add an event listener for the stateChange event, and compare the state property of the event data to the constants included in this class.

View the examples

See also

StateChangeEvent


Public Properties
 PropertyDefined By
  AIR-only isSupported : Boolean
[static] [read-only] Deterimines whether or not this native extension is supported on the device the app is running on.
AppActivityState
Public Methods
 MethodDefined By
  
Creates a new AppActivityState instance.
AppActivityState
  
AIR-only dispose():void
Properly shut down this native extension.
AppActivityState
  
Get the current activity state of the application.
AppActivityState
Events
 Event Summary Defined By
  This event is dispatched when a state change has occured in the application.AppActivityState
Public Constants
 ConstantDefined By
  AIR-only DESTROYED : String = destroyed
[static] The final call you receive before your activity is destroyed.
AppActivityState
  AIR-only PAUSED : String = paused
[static] Called when the system is about to start resuming a previous activity.
AppActivityState
  AIR-only RESTARTED : String = restarted
[static] Called after your activity has been stopped, prior to it being started again.
AppActivityState
  AIR-only RESUMED : String = resumed
[static] Called when the activity will start interacting with the user.
AppActivityState
  AIR-only STARTED : String = started
[static] Called when the activity is becoming visible to the user.
AppActivityState
  AIR-only STOPPED : String = stopped
[static] Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one.
AppActivityState
Property Detail
AIR-only isSupportedproperty
isSupported:Boolean  [read-only]

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Deterimines whether or not this native extension is supported on the device the app is running on.


Implementation
    public static function get isSupported():Boolean
Constructor Detail
AIR-only AppActivityState()Constructor
public function AppActivityState()

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Creates a new AppActivityState instance.

Method Detail
AIR-only dispose()method
public final function dispose():void

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Properly shut down this native extension.

AIR-only getAppActivityState()method 
public final function getAppActivityState():String

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Get the current activity state of the application. The value will be any of the following: started, restarted, resumed, paused, stopped, and destroyed.

Returns
StringString value representing the current state of the application.
Event Detail
AIR-only stateChange Event
Event Object Type: com.wadedwalker.nativeExtension.app.events.StateChangeEvent

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

This event is dispatched when a state change has occured in the application. The states are: started, restarted, resumed, paused, stopped, and destroyed.

This event has the following properties in addition to standard event properties:

PropertyValue
stateString value representing the current application activity state.

Constant Detail
AIR-only DESTROYEDConstant
public static const DESTROYED:String = destroyed

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The final call you receive before your activity is destroyed. This can happen either because the activity is finishing or because the system is temporarily destroying this instance of the activity to save space.

Note: This state may not happen, so it shouldn't be relied on for knowing if the application has been closed, quit, or crashed. A likely chance of this state change happening is an app playing a video/audio file or high CPU usage like playing a game.

AIR-only PAUSEDConstant 
public static const PAUSED:String = paused

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Called when the system is about to start resuming a previous activity.

Note: The most likely time this is called is if the user goes to the home screen or brings up the list of Recent Apps on the device.

AIR-only RESTARTEDConstant 
public static const RESTARTED:String = restarted

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Called after your activity has been stopped, prior to it being started again.

Note: This state change will occur on, but is not limited to, the following activities:

AIR-only RESUMEDConstant 
public static const RESUMED:String = resumed

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it. This should always occur the restarted state.

Note: This state change will occur on, but is not limited to, the following activities:

AIR-only STARTEDConstant 
public static const STARTED:String = started

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Called when the activity is becoming visible to the user.

Note: This state is highly unlikely to ever occur because the app will have been initialized and started before the native extension would have been able to initialize. Included in case developer wants to check for it anyway.

AIR-only STOPPEDConstant 
public static const STOPPED:String = stopped

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one. This may happen either because a new activity is being started, an existing one is being brought in front of this one, or this one is being destroyed.

Note: The most likely case of this state happening is if the user leaves the application by either going to the home screen, switching to a different app through the Recent Apps list, or the app was closed or quit. It should be safe to use this state to know if the application has been closed.

Examples
The following example shows how to listen for app state changes so that games can be paused/resumed, data can be saved/restored, etc when a state change occurs.
package {
    
    import flash.display.Sprite;
    import com.wadedwalker.nativeExtension.app.AppActivityState;
    import com.wadedwalker.nativeExtension.app.events.StateChangeEvent;
    
    final public class MyAndroidApp extends Sprite {
        
        private var _aas:AppActivityState;
        
        final public function MyAndroidApp() {
            _aas = new AppActivityState();
            _aas.addEventListner(StateChangeEvent.STATE_CHANGE, _onStageChange);
        }
        
        final private function _onStateChange(e:StateChangeEvent):void {
            switch (e.state) {
                case AppActivityState.DESTROYED:
                    // The final call you receive before your activity is destroyed.
                    
                case AppActivityState.PAUSED:
                    // Called when the system is about to start resuming a previous activity.
                    
                case AppActivityState.RESTARTED:
                    // Called after your activity has been stopped, prior to it being started again.
                    
                case AppActivityState.RESUMED:
                    // Called when the activity will start interacting with the user.
                    
                case AppActivityState.STARTED:
                    // Called when the activity is becoming visible to the user.
                    
                case AppActivityState.STOPPED:
                    // Called when the activity is no longer visible to the user, because another 
                    // activity has been resumed and is covering this one.
            }
        }
    }
}