Send an event to signal memory pressure (flutter/engine#3475)
See https://github.com/flutter/flutter/issues/7561
This commit is contained in:
@@ -151,4 +151,12 @@ public class FlutterActivity extends Activity {
|
||||
public FlutterView getFlutterView() {
|
||||
return flutterView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrimMemory(int level) {
|
||||
// Use a trim level delivered while the application is running so the
|
||||
// framework has a chance to react to the notification.
|
||||
if (level == TRIM_MEMORY_RUNNING_LOW)
|
||||
flutterView.onMemoryPressure();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +199,16 @@ public class FlutterView extends SurfaceView
|
||||
sendPlatformMessage("flutter/lifecycle", "AppLifecycleState.resumed", null);
|
||||
}
|
||||
|
||||
public void onMemoryPressure() {
|
||||
try {
|
||||
JSONObject message = new JSONObject();
|
||||
message.put("type", "memoryPressure");
|
||||
sendPlatformMessage("flutter/system", message.toString(), null);
|
||||
} catch (JSONException e) {
|
||||
Log.e(TAG, "Failed to serialize system event", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void pushRoute(String route) {
|
||||
try {
|
||||
final JSONArray args = new JSONArray();
|
||||
|
||||
Reference in New Issue
Block a user