title: Activity never becomes requested state "[DESTROYED, RESUMED, STARTED, CREATED]" (last lifecycle transition = "PRE_ON_CREATE")
body: <p>This is not a duplicate question.<br />
  I have already looked at similar questions. I have added the questions I have referred to at the last.</p>
  <p>My problem is that the test executes, but I have to open the app manually for every test.</p>
  <p><a href="https://i.stack.imgur.com/R4xRw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/R4xRw.png" alt="screenshot" /></a></p>
  <p>You can see that I had been waiting for 18 seconds before opening the app. It waits till I open the app manually or it shows this error after a timeout.</p>
  <blockquote>
  <p>Activity never becomes requested state &quot;[DESTROYED, RESUMED, STARTED, CREATED]&quot; (last lifecycle transition = &quot;PRE_ON_CREATE&quot;)</p>
  </blockquote>
  <p>From <a href="https://stackoverflow.com/questions/64458330/android-instrumented-test-throws-exception-activity-never-becomes-requested-sta">this post</a>, I assume the issue is with the device as I am using <code>Redmi Note 5</code>.<br />
  I have <code>disabled animations</code> as well as the <code>MIUI optimization</code> option.</p>
  <p>Any help is appreciated to run the tests on Xiaomi devices automatically.</p>
  <p>No point in running automated UI tests manually.</p>
  <p><strong>Update 1</strong><br />
  It executes only for launcher / main activity.<br />
  It is not working for other activities.</p>
  <p><strong>Update 2</strong><br />
  I also happen to have a Redmi 4. The tests work on that device as expected without any code changes.</p>
  <p><strong>Referred SO questions</strong></p>
  <ul>
  <li><a href="https://stackoverflow.com/q/53598321/9636037">AndroidX.Test ActivityScenario: java.lang.AssertionError: Activity never becomes requested state &quot;[RESUMED]&quot; (last lifecycle transition = &quot;STOPPED&quot;)</a></li>
  <li><a href="https://stackoverflow.com/questions/61477001/android-device-doesnt-launch-activities-on-the-screen-while-espresso-testing">Android device doesn&#39;t launch activities on the screen while espresso testing</a></li>
  <li><a href="https://stackoverflow.com/questions/62083769/activity-never-becomes-requested-state-in-ui-testing">Activity never becomes requested state in UI Testing</a></li>
  <li><a href="https://stackoverflow.com/questions/62952309/java-lang-assertionerror-activity-never-becomes-requested-state">java.lang.AssertionError: Activity never becomes requested state</a></li>
  <li><a href="https://stackoverflow.com/questions/64458330/android-instrumented-test-throws-exception-activity-never-becomes-requested-sta">Android instrumented test throws exception: Activity never becomes requested state &quot;[RESUMED, DESTROYED, STARTED, CREATED]&quot;</a></li>
  <li><a href="https://stackoverflow.com/questions/67537197/how-do-i-fix-this-error-java-lang-assertionerror-activity-never-becomes-request">How do I fix this error java.lang.AssertionError: Activity never becomes requested state &quot;[DESTROYED]&quot; (last lifecycle transition = &quot;RESUMED&quot;)</a></li>
  </ul>
  <p><strong>And related issues,</strong></p>
  <ul>
  <li><a href="https://github.com/android/android-test/issues/143" rel="noreferrer">https://github.com/android/android-test/issues/143</a></li>
  <li><a href="https://github.com/android/android-test/issues/496" rel="noreferrer">https://github.com/android/android-test/issues/496</a></li>
  </ul>
  <p>Adding code snippets and dependencies for anyone who wants to have a look,</p>
  <p><strong>Test code</strong></p>
  <pre><code>import androidx.test.core.app.ActivityScenario
  import androidx.test.espresso.Espresso.onView
  import androidx.test.espresso.assertion.ViewAssertions.matches
  import androidx.test.espresso.matcher.ViewMatchers.*
  import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
  import org.junit.Test
  import org.junit.runner.RunWith
  
  @RunWith(AndroidJUnit4ClassRunner::class)
  class MainActivityTest {
      @Test
      fun test_isActivityInView() {
          val activityScenario = ActivityScenario.launch(MainActivity::class.java)
          onView(withId(R.id.layout_activity_main)).check(matches(isDisplayed()))
      }
  }
  </code></pre>
  <p><strong>Dependencies</strong></p>
  <pre><code>testImplementation &quot;junit:junit:4.13.2&quot;
  androidTestImplementation &quot;androidx.test:core:1.4.0&quot;
  androidTestImplementation &quot;androidx.test:runner:1.4.0&quot;
  androidTestImplementation &quot;androidx.test:rules:1.4.0&quot;
  androidTestImplementation &quot;androidx.test.ext:junit-ktx:1.1.3&quot;
  androidTestImplementation &quot;androidx.test.espresso:espresso-core:3.4.0&quot;
  </code></pre>