android / architecture-samples

A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.
Apache License 2.0
44.5k stars 11.65k forks source link

[dev-hilt] cannot run tests error : java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState #769

Closed Aratnor closed 4 years ago

Aratnor commented 4 years ago

i got this error when i tried to run TaskDetailFragmentTest in dev-hilt branch. Full error log : 2020-11-05 17:24:40.901 10720-10744/com.example.android.architecture.blueprints.master E/MonitoringInstr: An exception is thrown from the runnable posted to the main thread java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at java.util.concurrent.FutureTask.report(FutureTask.java:123) at java.util.concurrent.FutureTask.get(FutureTask.java:193) at androidx.test.runner.MonitoringInstrumentation.runOnMainSync(MonitoringInstrumentation.java:435) at androidx.test.core.app.ActivityScenario.onActivity(ActivityScenario.java:564) at com.example.android.architecture.blueprints.todoapp.taskdetail.TaskDetailFragmentTest.activeTaskDetails_DisplayedInUi(TaskDetailFragmentTest.kt:122) at java.lang.reflect.Method.invoke(Native Method) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80) at dagger.hilt.android.internal.testing.MarkThatRulesRanRule$1.evaluate(MarkThatRulesRanRule.java:92) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56) at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2074) Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at androidx.fragment.app.FragmentManager.checkStateLoss(FragmentManager.java:1689) at androidx.fragment.app.FragmentManager.ensureExecReady(FragmentManager.java:1792) at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1812) at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:297) at com.example.android.architecture.blueprints.todoapp.taskdetail.TaskDetailFragmentTest$activeTaskDetails_DisplayedInUi$$inlined$launchFragmentInHiltContainer$1.perform(HiltExt.kt:59) at com.example.android.architecture.blueprints.todoapp.taskdetail.TaskDetailFragmentTest$activeTaskDetails_DisplayedInUi$$inlined$launchFragmentInHiltContainer$1.perform(Unknown Source:2) at androidx.test.core.app.ActivityScenario.lambda$onActivity$2$ActivityScenario(ActivityScenario.java:551) at androidx.test.core.app.ActivityScenario$$Lambda$4.run(Unknown Source:4) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 2020-11-05 17:24:40.901 10720-10744/com.example.android.architecture.blueprints.master E/MonitoringInstr: at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:2092) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 2020-11-05 17:24:40.901 10720-10744/com.example.android.architecture.blueprints.master E/TestRunner: failed: activeTaskDetails_DisplayedInUi(com.example.android.architecture.blueprints.todoapp.taskdetail.TaskDetailFragmentTest) 2020-11-05 17:24:40.901 10720-10744/com.example.android.architecture.blueprints.master E/TestRunner: ----- begin exception ----- 2020-11-05 17:24:40.902 10720-10744/com.example.android.architecture.blueprints.master E/TestRunner: java.lang.RuntimeException: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

Aratnor commented 4 years ago

Reason is device screen is off: https://stackoverflow.com/questions/57344170/java-lang-illegalstateexception-can-not-perform-this-action-after-onsaveinstanc