Skip to content

Commit

Permalink
Fix another instance of platform view breakage on Android 14 (#52980)
Browse files Browse the repository at this point in the history
When you background an activity via the back-gesture the onTrimMemory callback is not invoked but the buggy Android behaviour still occurs.

Workaround this by faking an onTrimMemory callback in the `Activity#onStop` callback.

Fixes #148662
Related #146499

Tested manually on a Pixel 7 Pro running Android 14.
  • Loading branch information
johnmccutchan authored May 22, 2024
1 parent 8b094fb commit 97e740e
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
Expand Down Expand Up @@ -645,6 +646,12 @@ void onStop() {
// See https://github.com/flutter/flutter/issues/93276
previousVisibility = flutterView.getVisibility();
flutterView.setVisibility(View.GONE);
if (flutterEngine != null) {
// When an Activity is stopped it won't have its onTrimMemory callback invoked. Normally,
// this isn't a problem but because of a bug in some builds of Android 14 we must act as
// if the onTrimMemory callback has been called.
flutterEngine.getRenderer().onTrimMemory(ComponentCallbacks2.TRIM_MEMORY_BACKGROUND);
}
}

/**
Expand Down

0 comments on commit 97e740e

Please sign in to comment.