Send an event to signal memory pressure (flutter/engine#3475)

See https://github.com/flutter/flutter/issues/7561
This commit is contained in:
Jason Simmons
2017-03-14 15:42:30 -07:00
committed by GitHub
parent 76d4e76b08
commit b2715565a0
2 changed files with 18 additions and 0 deletions

View File

@@ -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();
}
}

View File

@@ -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();