android - Can not do UI work in method finish() of Activity when using Espresso rules? -


i'm using espresso ui test android app.

following official guide, used activitytestrule launch activity under test. when test finishes, crash occurred.

stack trace is

android.view.viewrootimpl$calledfromwrongthreadexception: original thread created view hierarchy can touch views. @ android.view.viewrootimpl.checkthread(viewrootimpl.java:6247) @ android.view.viewrootimpl.playsoundeffect(viewrootimpl.java:5222) @ android.view.view.playsoundeffect(view.java:17876) @ android.view.view.performclick(view.java:4755) @ com.example.android.activityinstrumentation.readexternalfileactivity.finish(readexternalfileactivity.java:196) @ android.support.test.rule.activitytestrule.finishactivity(activitytestrule.java:234) @ android.support.test.rule.activitytestrule$activitystatement.evaluate(activitytestrule.java:259) @ org.junit.rules.runrules.evaluate(runrules.java:20) @ org.junit.runners.parentrunner.runleaf(parentrunner.java:325) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:78) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:57) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.junit.runners.suite.runchild(suite.java:128) @ org.junit.runners.suite.runchild(suite.java:27) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.junit.runner.junitcore.run(junitcore.java:137) @ org.junit.runner.junitcore.run(junitcore.java:115) @ android.support.test.internal.runner.testexecutor.execute(testexecutor.java:59) @ android.support.test.runner.androidjunitrunner.onstart(androidjunitrunner.java:262) @ android.app.instrumentation$instrumentationthread.run(instrumentation.java:1837) 

throw call stack, found androidjunitrunner tried call finish() of activity non-ui thread, caused crash.

my app overrides method finish() of activity, popping dialog ask user confirm exit or not, should executed on ui thread.

does mean, can not ui work in finish() method of activity when using espresso? or bug of espresso?

do not ui work in finish().

finish() not purpose. finish() happens after user says yes dialog.

the activity should gone screen time reaches it. i'm little surprised took test-case see fail.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -