public class RestorationChannel extends Object
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()
.
Modifier and Type | Field and Description |
---|---|
boolean |
waitForRestorationData
Whether the channel delays responding to the framework's initial request for restoration data
until
setRestorationData has been called. |
Constructor and Description |
---|
RestorationChannel(DartExecutor dartExecutor,
boolean waitForRestorationData) |
Modifier and Type | Method and Description |
---|---|
void |
clearData()
Clears the current restoration data.
|
byte[] |
getRestorationData()
Obtain the most current restoration data that the framework has provided.
|
void |
setRestorationData(byte[] data)
Set the restoration data from which the framework will restore its state.
|
public final boolean waitForRestorationData
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.
public RestorationChannel(@NonNull DartExecutor dartExecutor, @NonNull boolean waitForRestorationData)
public byte[] getRestorationData()
public void setRestorationData(byte[] data)
public void clearData()
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.