Class RestorationChannel


  • public class RestorationChannel
    extends Object
    System channel to exchange restoration data between framework and engine.

    The engine can obtain the current restoration data from the framework via this channel to store it on disk and - when the app is relaunched - provide the stored data back to the framework to recreate the original state of the app.

    The channel can be configured to delay responding to the framework's request for restoration data via waitForRestorationData until the engine-side has provided the data. This is useful when the engine is pre-warmed at a point in the application's life cycle where the restoration data is not available yet. For example, if the engine is pre-warmed as part of the Application before an Activity is created, this flag should be set to true because Android will only provide the restoration data to the Activity during the onCreate callback.

    The current restoration data provided by the framework can be read via getRestorationData().

    • Field Detail

      • waitForRestorationData

        public final boolean waitForRestorationData
        Whether the channel delays responding to the framework's initial request for restoration data until setRestorationData has been called.

        If the engine never calls setRestorationData this flag must be set to false. If set to true, the engine must call setRestorationData either with the actual restoration data as argument or null if it turns out that there is no restoration data.

        If the response to the framework's request for restoration data is not delayed until the data has been set via setRestorationData, the framework may intermittently initialize itself to default values until the restoration data has been made available. Setting this flag to true avoids that extra work.

    • Constructor Detail

      • RestorationChannel

        public RestorationChannel​(@NonNull
                                  DartExecutor dartExecutor,
                                  @NonNull
                                  boolean waitForRestorationData)
    • Method Detail

      • getRestorationData

        @Nullable
        public byte[] getRestorationData()
        Obtain the most current restoration data that the framework has provided.
      • setRestorationData

        public void setRestorationData​(@NonNull
                                       byte[] data)
        Set the restoration data from which the framework will restore its state.
      • clearData

        public void clearData()
        Clears the current restoration data.

        This should be called just prior to a hot restart. Otherwise, after the hot restart the state prior to the hot restart will get restored.