diff --git a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivity.java b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivity.java index 0d4f3c77ca..9b7427238c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivity.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivity.java @@ -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(); + } } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java index 28181b65ff..82821f8df2 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterView.java @@ -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();