AppState can tell you if the app is in the foreground or background,
and notify you when the state changes.
AppState is frequently used to determine the intent and proper behavior when handling push notifications.
active- The app is running in the foreground
background- The app is running in the background. The user is either in another app or on the home screen
inactive- This is a state that occurs when transitioning between foreground & background, and during periods of inactivity such as entering the Multitasking view or in the event of an incoming call
For more information, see Apple's documentation
To see the current state, you can check
will be kept up-to-date. However,
currentState will be null at launch
AppState retrieves it over the bridge.
This example will only ever appear to say "Current state is: active" because
the app is only visible to the user when in the
active state, and the null
state will happen only momentarily.
Add a handler to AppState changes by listening to the
change event type
and providing the handler
TODO: now that AppState is a subclass of NativeEventEmitter, we could deprecate
removeEventListener and just use
listener.remove() directly. That will be a breaking change though, as both
the method and event names are different (addListener events are currently
required to be globally unique).
Remove a handler by passing the
change event type and the handler
You can edit the content above on GitHub and send us a pull request!
|Edit on GitHub|