diff --git a/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java b/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java
index <HASH>..<HASH> 100755
--- a/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java
+++ b/robolectric/src/main/java/org/robolectric/android/internal/AndroidTestEnvironment.java
@@ -176,6 +176,8 @@ public class AndroidTestEnvironment implements TestEnvironment {
     RuntimeEnvironment.setAndroidFrameworkJarPath(sdkJarPath);
     Bootstrap.setDisplayConfiguration(androidConfiguration, displayMetrics);
     RuntimeEnvironment.setActivityThread(ReflectionHelpers.newInstance(ActivityThread.class));
+    ReflectionHelpers.setStaticField(
+        ActivityThread.class, "sMainThreadHandler", new Handler(Looper.myLooper()));
 
     Instrumentation instrumentation = createInstrumentation();
     InstrumentationRegistry.registerInstance(instrumentation, new Bundle());
@@ -278,9 +280,6 @@ public class AndroidTestEnvironment implements TestEnvironment {
 
     shadowActivityThread.setCompatConfiguration(androidConfiguration);
 
-    ReflectionHelpers.setStaticField(
-        ActivityThread.class, "sMainThreadHandler", new Handler(Looper.myLooper()));
-
     Bootstrap.setUpDisplay();
     activityThread.applyConfigurationToResources(androidConfiguration);
Eagerly instantiate ActivityThread's main handler

Instantiating it inside installAndCreateApplication is no longer necessarily correct, as that can be called from a background thread

PiperOrigin-RevId: <I>