Skip to content

Commit 093c4ed

Browse files
authored
Revert "Make FlutterFragment usable without requiring it to be attached to an Android Activity. (flutter#27332)" (flutter#27382)
This reverts commit 317166d.
1 parent 317166d commit 093c4ed

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,23 +276,23 @@ View onCreateView(
276276
if (host.getRenderMode() == RenderMode.surface) {
277277
FlutterSurfaceView flutterSurfaceView =
278278
new FlutterSurfaceView(
279-
host.getContext(), host.getTransparencyMode() == TransparencyMode.transparent);
279+
host.getActivity(), host.getTransparencyMode() == TransparencyMode.transparent);
280280

281281
// Allow our host to customize FlutterSurfaceView, if desired.
282282
host.onFlutterSurfaceViewCreated(flutterSurfaceView);
283283

284284
// Create the FlutterView that owns the FlutterSurfaceView.
285-
flutterView = new FlutterView(host.getContext(), flutterSurfaceView);
285+
flutterView = new FlutterView(host.getActivity(), flutterSurfaceView);
286286
} else {
287-
FlutterTextureView flutterTextureView = new FlutterTextureView(host.getContext());
287+
FlutterTextureView flutterTextureView = new FlutterTextureView(host.getActivity());
288288

289289
flutterTextureView.setOpaque(host.getTransparencyMode() == TransparencyMode.opaque);
290290

291291
// Allow our host to customize FlutterSurfaceView, if desired.
292292
host.onFlutterTextureViewCreated(flutterTextureView);
293293

294294
// Create the FlutterView that owns the FlutterTextureView.
295-
flutterView = new FlutterView(host.getContext(), flutterTextureView);
295+
flutterView = new FlutterView(host.getActivity(), flutterTextureView);
296296
}
297297

298298
// Add listener to be notified when Flutter renders its first frame.

shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -378,31 +378,21 @@ public void itDoesNotAttachFlutterToTheActivityIfNotDesired() {
378378
// Declare that the host does NOT want Flutter to attach to the surrounding Activity.
379379
when(mockHost.shouldAttachEngineToActivity()).thenReturn(false);
380380

381-
// getActivity() returns null if the activity is not attached
382-
when(mockHost.getActivity()).thenReturn(null);
383-
384381
// Create the real object that we're testing.
385382
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
386383

387384
// --- Execute the behavior under test ---
388385
// Flutter is attached to the surrounding Activity in onAttach.
389386
delegate.onAttach(RuntimeEnvironment.application);
390387

391-
// Make sure all of the other lifecycle methods can run safely as well
392-
// without a valid Activity
393-
delegate.onCreateView(null, null, null);
394-
delegate.onStart();
395-
delegate.onResume();
396-
delegate.onPause();
397-
delegate.onStop();
398-
delegate.onDestroyView();
388+
// Verify that the ActivityControlSurface was NOT told to attach to an Activity.
389+
verify(mockFlutterEngine.getActivityControlSurface(), never())
390+
.attachToActivity(any(Activity.class), any(Lifecycle.class));
399391

400392
// Flutter is detached from the surrounding Activity in onDetach.
401393
delegate.onDetach();
402394

403-
// Verify that the ActivityControlSurface was NOT told to attach or detach to an Activity.
404-
verify(mockFlutterEngine.getActivityControlSurface(), never())
405-
.attachToActivity(any(Activity.class), any(Lifecycle.class));
395+
// Verify that the ActivityControlSurface was NOT told to detach from the Activity.
406396
verify(mockFlutterEngine.getActivityControlSurface(), never()).detachFromActivity();
407397
}
408398

0 commit comments

Comments
 (0)