Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Package Functions | List of all members
io.flutter.embedding.engine.systemchannels.RestorationChannel Class Reference

Public Member Functions

 RestorationChannel ( @NonNull DartExecutor dartExecutor, @NonNull boolean waitForRestorationData)
 
byte[] getRestorationData ()
 
void setRestorationData (@NonNull byte[] data)
 
void clearData ()
 

Public Attributes

final boolean waitForRestorationData
 

Package Functions

 RestorationChannel (MethodChannel channel, @NonNull boolean waitForRestorationData)
 

Detailed Description

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()
.

Definition at line 34 of file RestorationChannel.java.

Constructor & Destructor Documentation

◆ RestorationChannel() [1/2]

io.flutter.embedding.engine.systemchannels.RestorationChannel.RestorationChannel ( @NonNull DartExecutor  dartExecutor,
@NonNull boolean  waitForRestorationData 
)
inline

Definition at line 37 of file RestorationChannel.java.

38 {
39 this(
40 new MethodChannel(dartExecutor, "flutter/restoration", StandardMethodCodec.INSTANCE),
42 }

◆ RestorationChannel() [2/2]

io.flutter.embedding.engine.systemchannels.RestorationChannel.RestorationChannel ( MethodChannel  channel,
@NonNull boolean  waitForRestorationData 
)
inlinepackage

Definition at line 44 of file RestorationChannel.java.

44 {
45 this.channel = channel;
46 this.waitForRestorationData = waitForRestorationData;
47
48 channel.setMethodCallHandler(handler);
49 }

Member Function Documentation

◆ clearData()

void io.flutter.embedding.engine.systemchannels.RestorationChannel.clearData ( )
inline

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.

Definition at line 131 of file RestorationChannel.java.

131 {
132 restorationData = null;
133 }

◆ getRestorationData()

byte[] io.flutter.embedding.engine.systemchannels.RestorationChannel.getRestorationData ( )
inline

Obtain the most current restoration data that the framework has provided.

Definition at line 77 of file RestorationChannel.java.

77 {
78 return restorationData;
79 }

◆ setRestorationData()

void io.flutter.embedding.engine.systemchannels.RestorationChannel.setRestorationData ( @NonNull byte[]  data)
inline

Set the restoration data from which the framework will restore its state.

Definition at line 82 of file RestorationChannel.java.

82 {
83 engineHasProvidedData = true;
84 if (pendingFrameworkRestorationChannelRequest != null) {
85 // If their is a pending request from the framework, answer it.
86 pendingFrameworkRestorationChannelRequest.success(packageData(data));
87 pendingFrameworkRestorationChannelRequest = null;
88 restorationData = data;
89 } else if (frameworkHasRequestedData) {
90 // If the framework has previously received the engine's restoration data, push the new data
91 // directly to it. This case can happen when "waitForRestorationData" is false and the
92 // framework retrieved the restoration state before it was set via this method.
93 // Experimentally, this can also be used to restore a previously used engine to another state,
94 // e.g. when the engine is attached to a new activity.
95 channel.invokeMethod(
96 "push",
97 packageData(data),
98 new MethodChannel.Result() {
99 @Override
100 public void success(Object result) {
101 restorationData = data;
102 }
103
104 @Override
105 public void error(String errorCode, String errorMessage, Object errorDetails) {
106 Log.e(
107 TAG,
108 "Error "
109 + errorCode
110 + " while sending restoration data to framework: "
111 + errorMessage);
112 }
113
114 @Override
115 public void notImplemented() {
116 // Nothing to do.
117 }
118 });
119 } else {
120 // Otherwise, just cache the data until the framework asks for it.
121 restorationData = data;
122 }
123 }
const uint8_t uint32_t uint32_t GError ** error
void Log(const char *format,...) SK_PRINTF_LIKE(1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

Member Data Documentation

◆ waitForRestorationData

final boolean io.flutter.embedding.engine.systemchannels.RestorationChannel.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.

Definition at line 64 of file RestorationChannel.java.


The documentation for this class was generated from the following file: