Monitor the application lifecycle from JS
The lifecycle of an app is the time from when your app starts to the time it terminates. During this time the app will go through a number of states.
The Lifecycle module allows you query the current state and also be alerted when the app changes state.
Your app is not the app the user is interactive with right now and so the operating system has put it into a 'sleep' state.
Whilst your app is in this state is is not allowed to run code, but you don't have to worry about this as Fuse will ensure your JS/UX is not doing something when it shouldn't.
Your app is front and center on the user's device but they cannot yet interact with it. The main reason to be in this state is that the user has opened the notification bar on iOS or Android.
Your app is now in the foreground and is accepting input from the user.
It would be hard to work with app lifecycle if your app could just jump around the states randomly. Instead we guarentee the following flow through the states:
Starting ↓ Background ⟷ Foreground ⟷ Interactive ↓ Terminating
You may be wondering why there is no
terminating event. The reason is that on mobile
platforms the OS doesn't promise to call you when terminating your app. It may, but in
certain circumstances (low memory, emergency phone call, etc) it won't.
Because of this the guides for mobile platforms strongly advise against using the
event as a cue that the app is shutting down, instead you should be regularly 'checkpointing'
your app so you can recover from any kind of shutdown.
Given that we are not meant to use it, we have opted not to expose the event.
In the above example we're using the EventEmitter
on method to listen to the different events.
We're also using the EventEmitter
observe method on the
"stateChanged" event to get an Observable containing the current state.
- FuseJS 1.11.2
Interface of Lifecycle
FOREGROUND : int js
INTERACTIVE : int js
Inherited from NativeEventEmitterModule
emit("error", reason) on the underlying JS EventEmitter.
emit("error", new Error(reason)) on the underlying JS EventEmitter.
Connect a Callback to an event.
Inherited from NativeModule
Inherited from Module
GetFile : FileSource uno
Returns the file source that will be watched by the Context for changes in Fuse preview. Override in subclasses and return correct file source to support live updates in Fuse preview.