Skip to main content

The Page Lifecycle

An FMC page has a lifecycle similar to a Subscriptions. It is automatically resumed, paused and destroyed by the FMC screen. Additionally, it has an initialization callback for when it is first created. Considering this, it is important to understand this lifecycle inorder to properly manage any data the page depends on.

Binding subscriptions to the page's lifecycle

It is possible to easily bind any Subscription to the lifecycle of a page by using the addBinding() method on the page.

By doing this, any subscription bound in this way will be resumed, paused and destroyed at the same time as the page.

caution

Binding subscriptions is not desirable if you wish for the page to consume data even when it is paused - for example, if you wish to update a data store on a page when flight planning events are received, subscriptions will not be notified of such events if they are paused along with their containing page.

You can work around this by either

a) not binding the subscription to the page lifetime; or b) re-generating the data stored in the page from the current state in the page onResume() callback.

Page lifecycle callbacks

The follow callbacks are available to be overridden on AbstractFmcPage:

onInit

Called after the page is constructed.

onResume

Called when the page is navigated to.

onPaused

Called when the page is navigated away from.

onDestroyed

Called when the page is being destroyed.

Page lifecycle policies

AbstractFmcPage has a static member called lifecyclePolicy, which can be overridden to one of the following two values:

  • Singleton (default) - the page is only created once, when it is first navigated to, and always kept in memory afterwards;
  • Transient - the page is created every time it is navigated to.