Make fragment leftover from an attach/detach race slightly safer (flutter/engine#29908)

This commit is contained in:
陈昱
2021-12-03 05:19:01 +08:00
committed by GitHub
parent d2614e6185
commit 30c4de0797
2 changed files with 7 additions and 1 deletions

View File

@@ -784,7 +784,9 @@ public class FlutterFragment extends Fragment
// possible.
@ActivityCallThrough
public void onPostResume() {
delegate.onPostResume();
if (stillAttachedForEvent("onPostResume")) {
delegate.onPostResume();
}
}
@Override

View File

@@ -121,9 +121,11 @@ public class FlutterFragmentTest {
fragment.setDelegate(mockDelegate);
fragment.onStart();
fragment.onResume();
fragment.onPostResume();
verify(mockDelegate, times(1)).onStart();
verify(mockDelegate, times(1)).onResume();
verify(mockDelegate, times(1)).onPostResume();
fragment.onPause();
fragment.detachFromFlutterEngine();
@@ -136,9 +138,11 @@ public class FlutterFragmentTest {
fragment.onStart();
fragment.onResume();
fragment.onPostResume();
// No more events through to the delegate.
verify(mockDelegate, times(1)).onStart();
verify(mockDelegate, times(1)).onResume();
verify(mockDelegate, times(1)).onPostResume();
fragment.onDestroy();
// 1 time same as before.