Flutter Engine
The Flutter Engine
RobolectricFlutterActivity.java
Go to the documentation of this file.
1package io.flutter.embedding.android;
2
3import android.content.Intent;
4import androidx.annotation.NonNull;
5import org.robolectric.Robolectric;
6import org.robolectric.android.controller.ActivityController;
7
8/**
9 * Creates a {@code FlutterActivity} for use by test code that do not sit within the {@code
10 * io.flutter.embedding.android} package, and offers public access to some package private
11 * properties of {@code FlutterActivity} for testing purposes.
12 */
14 /**
15 * Creates a {@code FlutterActivity} that is controlled by Robolectric, which otherwise can not be
16 * done in a test outside of the io.flutter.embedding.android package.
17 */
18 @NonNull
19 public static FlutterActivity createFlutterActivity(@NonNull Intent intent) {
20 ActivityController<FlutterActivity> activityController =
21 Robolectric.buildActivity(FlutterActivity.class, intent);
22 FlutterActivity flutterActivity = activityController.get();
23 flutterActivity.setDelegate(new FlutterActivityAndFragmentDelegate(flutterActivity));
24 return flutterActivity;
25 }
26
27 /**
28 * Returns a given {@code FlutterActivity}'s {@code BackgroundMode} for use by tests that do not
29 * sit in the {@code io.flutter.embedding.android} package.
30 */
31 @NonNull
32 public static FlutterActivityLaunchConfigs.BackgroundMode getBackgroundMode(
33 @NonNull FlutterActivity activity) {
34 return activity.getBackgroundMode();
35 }
36}
void setDelegate(@NonNull FlutterActivityAndFragmentDelegate delegate)
static FlutterActivityLaunchConfigs.BackgroundMode getBackgroundMode( @NonNull FlutterActivity activity)
static FlutterActivity createFlutterActivity(@NonNull Intent intent)