Preserving and restoring application state in xamarin forms

1.2k Views Asked by At

In Prism for xamarin forms, How does the navigation stack is restored when application is resumed after got killed by OS?

1

There are 1 best solutions below

1
Bruno Caceiro On

Here you can check the official Prism documentation about Application Lifecycle Management.

The typical application lifecycle events are:

  • Initializing - This happens the first time the app is launched.
  • Resuming - This happens every time we restore the app from the background after it has been suspended.
  • Sleeping - This happens when the OS decides to freeze our app after it has gone in background

The methods:

  protected override void OnResume()
        {
            base.OnResume();

            // TODO: Refresh network data, perform UI updates, and reacquire resources like cameras, I/O devices, etc.

        }

        protected override void OnSleep()
        {
            base.OnSleep();

            // TODO: This is the time to save app data in case the process is terminated.
            // This is the perfect timing to release exclusive resources (camera, I/O devices, etc...)

        }

Facing this, you have methods that are called in each situation. You should override them and, depending on your needs, implement the requirements that you desire.