具有不确定ProgressBar的UI的“java.lang.RuntimeException:无法启动意图”

时间:2015-05-26 21:26:35

标签: android android-intent android-progressbar android-espresso android-instrumentation

使用AndroidJUnitRunner显示不确定的ProgressBar是否存在任何已知问题?我在测试期间遇到了这个错误:

  

05-26 15:22:48.504 1003-1016 /? I / TestRunner的:   java.lang.RuntimeException:无法启动intent Intent {   act = android.intent.action.MAIN flg = 0x14000000   45以内的cmp = com.cookbrite.dev / com.cookbrite.ui.HomeListActivity}   秒。也许主线程并没有在一个合理的范围内闲置   多少时间?可能会有动画或其他东西不断   重新粉刷屏幕。或者活动正在进行网络呼叫   创建?请参阅threaddump日志。最后一次供您参考   在您的活动启动请求之前,事件队列处于空闲状态   1432668122421现在队列最后一次空闲是:   1432668122421.如果这些数字相同,您的活动可能会占用事件队列。

堆栈跟踪是:

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)

上述超时触发的线程转储显示似乎涉及ProgressBar

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 个答案:

答案 0 :(得分:1)

我认为你不能真正测试进度条以确定它们是否完成。

我们使用进度条只是为了显示我们的时间(例如30天周期中的第7天所以我们的进度条从未完成)。为避免此问题,我们必须为我们的应用程序使用不同的API级别。我们似乎只对API级别为21的仿真器出现此问题。一旦我们将仿真器切换到API级别19,我们的测试就成功了。

注意:我们在使用普通视图更改progressBar方面也取得了一些成功,但我们认为这比我们喜欢的更加笨拙。