问题
Are there any known issues with displaying indeterminate ProgressBar
s with the AndroidJUnitRunner? I'm hitting this error during tests:
05-26 15:22:48.504 1003-1016/? I/TestRunner﹕ java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.cookbrite.dev/com.cookbrite.ui.HomeListActivity } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1432668122421 and now the last time the queue went idle was: 1432668122421. If these numbers are the same your activity might be hogging the event queue.
The stack trace is:
05-26 15:22:48.504 1003-1016/? I/TestRunner﹕ java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.cookbrite.dev/com.cookbrite.ui.HomeListActivity } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1432668122421 and now the last time the queue went idle was: 1432668122421. If these numbers are the same your activity might be hogging the event queue.
at android.support.test.runner.MonitoringInstrumentation.startActivitySync(MonitoringInstrumentation.java:274)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:104)
at com.cookbrite.step2_functional.ui.homelist.HomeListFragmentLoadingTest.testLoadingSpinner(HomeListFragmentLoadingTest.java:40)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at com.cookbrite.util.BaseBlackBoxTest.doRunTest(BaseBlackBoxTest.java:300)
at com.cookbrite.util.BaseBlackBoxTest.access$000(BaseBlackBoxTest.java:44)
at com.cookbrite.util.BaseBlackBoxTest$1.call(BaseBlackBoxTest.java:271)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)
The thread dump triggered by the above timeout shows the ProgressBar
appears to be involved:
05-26 15:22:48.135 1003-1018/? E/THREAD_STATE﹕ Thread[main,5,main]
android.graphics.Canvas.native_drawBitmap(Native Method)
android.graphics.Canvas.drawBitmap(Canvas.java:1160)
android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:440)
android.graphics.drawable.RotateDrawable.draw(RotateDrawable.java:88)
android.graphics.drawable.LayerDrawable.draw(LayerDrawable.java:345)
android.widget.ProgressBar.onDraw(ProgressBar.java:1052)
android.view.View.draw(View.java:13944)
android.view.View.draw(View.java:13825)
android.view.ViewGroup.drawChild(ViewGroup.java:3086)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
android.view.View.draw(View.java:13823)
android.view.ViewGroup.drawChild(ViewGroup.java:3086)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
android.view.View.draw(View.java:13947)
android.view.View.draw(View.java:13825)
android.view.ViewGroup.drawChild(ViewGroup.java:3086)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
android.view.View.draw(View.java:13823)
android.view.ViewGroup.drawChild(ViewGroup.java:3086)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
android.view.View.draw(View.java:13947)
android.widget.FrameLayout.draw(FrameLayout.java:467)
android.view.View.draw(View.java:13825)
android.view.ViewGroup.drawChild(ViewGroup.java:3086)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
android.view.View.draw(View.java:13823)
android.view.ViewGroup.drawChild(ViewGroup.java:3086)
android.view.ViewGroup.dispatchDraw(ViewGroup.java:2923)
android.view.View.draw(View.java:13947)
android.widget.FrameLayout.draw(FrameLayout.java:467)
com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2224)
android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2482)
android.view.ViewRootImpl.draw(ViewRootImpl.java:2395)
android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2239)
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1872)
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
android.view.Choreographer.doCallbacks(Choreographer.java:562)
android.view.Choreographer.doFrame(Choreographer.java:532)
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
android.os.Handler.handleCallback(Handler.java:730)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:5103)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:525)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
dalvik.system.NativeStart.main(Native Method)
Thread[Binder_2,5,main]
dalvik.system.NativeStart.run(Native Method)
Thread[JDWP,5,system]
dalvik.system.NativeStart.run(Native Method)
Thread[pool-1-thread-1,5,main]
java.lang.Object.wait(Native Method)
java.lang.Object.wait(Object.java:364)
android.app.Instrumentation.startActivitySync(Instrumentation.java:403)
android.support.test.runner.MonitoringInstrumentation.access$101(MonitoringInstrumentation.java:69)
android.support.test.runner.MonitoringInstrumentation$3.call(MonitoringInstrumentation.java:265)
android.support.test.runner.MonitoringInstrumentation$3.call(MonitoringInstrumentation.java:262)
java.util.concurrent.FutureTask.run(FutureTask.java:234)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
java.lang.Thread.run(Thread.java:841)
Thread[pool-5-thread-1,5,main]
dalvik.system.VMStack.getThreadStackTrace(Native Method)
java.lang.Thread.getStackTrace
回答1:
I don't think you can actually test progress bars to see if they finish.
We used progress bars just as a way to show how far we were in time (for example day 7 out of a 30 day cycle so our progress bar never finished). To avoid this issue we had to use a different API level for our app. We seemed to only have this problem with an emulator with an API level of 21. Once we switched our emulator to API level of 19 our tests succeeded.
Note: We also had some success with changing the progressBar with plain views for the tests, but we decided that was more hacky than we liked.
来源:https://stackoverflow.com/questions/30469240/java-lang-runtimeexception-could-not-launch-intent-for-ui-with-indeterminate