diff options
Diffstat (limited to 'robolectric/src/main/java/org/robolectric/android/internal/RoboMonitoringInstrumentation.java')
-rw-r--r-- | robolectric/src/main/java/org/robolectric/android/internal/RoboMonitoringInstrumentation.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/robolectric/src/main/java/org/robolectric/android/internal/RoboMonitoringInstrumentation.java b/robolectric/src/main/java/org/robolectric/android/internal/RoboMonitoringInstrumentation.java index bfd3104af..a9665b706 100644 --- a/robolectric/src/main/java/org/robolectric/android/internal/RoboMonitoringInstrumentation.java +++ b/robolectric/src/main/java/org/robolectric/android/internal/RoboMonitoringInstrumentation.java @@ -35,6 +35,7 @@ import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nullable; import org.robolectric.Robolectric; @@ -62,6 +63,8 @@ public class RoboMonitoringInstrumentation extends Instrumentation { private final IntentMonitorImpl intentMonitor = new IntentMonitorImpl(); private final List<ActivityController<?>> createdActivities = new ArrayList<>(); + private final AtomicBoolean attachedConfigListener = new AtomicBoolean(); + /** * Sets up lifecycle monitoring, and argument registry. * @@ -74,13 +77,6 @@ public class RoboMonitoringInstrumentation extends Instrumentation { ActivityLifecycleMonitorRegistry.registerInstance(lifecycleMonitor); ApplicationLifecycleMonitorRegistry.registerInstance(applicationMonitor); IntentMonitorRegistry.registerInstance(intentMonitor); - if (!Boolean.getBoolean("robolectric.createActivityContexts")) { - // To avoid infinite recursion listen to the system resources, this will be updated before - // the application resources but because activities use the application resources they will - // get updated by the first activity (via updateConfiguration). - shadowOf(Resources.getSystem()).addConfigurationChangeListener(this::updateConfiguration); - } - super.onCreate(arguments); } @@ -115,6 +111,15 @@ public class RoboMonitoringInstrumentation extends Instrumentation { } catch (ClassNotFoundException e) { throw new RuntimeException("Could not load activity " + ai.name, e); } + + if (attachedConfigListener.compareAndSet(false, true) + && !Boolean.getBoolean("robolectric.createActivityContexts")) { + // To avoid infinite recursion listen to the system resources, this will be updated before + // the application resources but because activities use the application resources they will + // get updated by the first activity (via updateConfiguration). + shadowOf(Resources.getSystem()).addConfigurationChangeListener(this::updateConfiguration); + } + AtomicReference<ActivityController<? extends Activity>> activityControllerReference = new AtomicReference<>(); ShadowInstrumentation.runOnMainSyncNoIdle( |