来自Google Analytics for Android的RuntimeException“向死线程上的处理程序发送消息”

时间:2010-07-12 15:39:04

标签: android google-analytics analytics handler dispatch

我正在使用Google Analytics for Android来跟踪Android应用上的活动和网页浏览量。在调用跟踪器的调度方法时,我收到一个RuntimeException:

07-12 18:02:05.594: WARN/MessageQueue(12823): Handler{44a08620} sending message to a Handler on a dead thread
07-12 18:02:05.594: WARN/MessageQueue(12823): java.lang.RuntimeException: Handler{44a08620} sending message to a Handler on a dead thread
07-12 18:02:05.594: WARN/MessageQueue(12823):     at android.os.MessageQueue.enqueueMessage(MessageQueue.java:179)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at android.os.Handler.sendMessageAtTime(Handler.java:457)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at android.os.Handler.sendMessageDelayed(Handler.java:430)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at android.os.Handler.post(Handler.java:248)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.google.android.apps.analytics.NetworkDispatcher$DispatcherThread.dispatchEvents(Unknown Source)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.google.android.apps.analytics.NetworkDispatcher.dispatchEvents(Unknown Source)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.google.android.apps.analytics.GoogleAnalyticsTracker.dispatch(Unknown Source)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.company.activity.set(MyActivity.java:177)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.company.activity.access$34(MyActivity.java:175)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.company.activity.$45.onClick(MyActivity.java:1982)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at android.os.Looper.loop(Looper.java:123)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at java.lang.reflect.Method.invokeNative(Native Method)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at java.lang.reflect.Method.invoke(Method.java:521)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-12 18:02:05.594: WARN/MessageQueue(12823):     at dalvik.system.NativeStart.main(Native Method)

- EDIT-- 起初我确信它与我的跟踪器的位置有关,把它放在onResume,Threads等等,神奇地让它抛出异常。事实证明,Google's own example code(也可以在他们的SDK下载中使用)也会抛出此异常:

>07-12 23:47:09.343: WARN/MessageQueue(18468): null sending message to a Handler on a dead thread
07-12 23:47:09.343: WARN/MessageQueue(18468): java.lang.RuntimeException: null sending message to a Handler on a dead thread
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.os.MessageQueue.enqueueMessage(MessageQueue.java:179)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.os.Looper.quit(Looper.java:173)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at com.google.android.apps.analytics.NetworkDispatcher.stop(Unknown Source)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at com.google.android.apps.analytics.NetworkDispatcher.init(Unknown Source)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at com.google.android.apps.analytics.GoogleAnalyticsTracker.start(Unknown Source)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at com.google.android.apps.analytics.GoogleAnalyticsTracker.start(Unknown Source)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at com.google.android.apps.analytics.GoogleAnalyticsTracker.start(Unknown Source)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at com.google.android.apps.analytics.sample.AnalyticsSample.onCreate(AnalyticsSample.java:23)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3815)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.app.ActivityThread.access$2400(ActivityThread.java:125)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.os.Looper.loop(Looper.java:123)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at java.lang.reflect.Method.invokeNative(Native Method)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at java.lang.reflect.Method.invoke(Method.java:521)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-12 23:47:09.343: WARN/MessageQueue(18468):     at dalvik.system.NativeStart.main(Native Method)

当您强制销毁原始活动(即更改方向,转到主屏幕等)时会发生这种情况。我无法通过onSavedInstance存储原始跟踪器对象,因为跟踪器不是Parcelable。任何其他想法,线索如何摆脱这个错误?

- EDIT-- 更奇怪的是,这似乎也造成了以下问题:

>07-13 00:50:02.581: WARN/googleanalytics(27605): Dispatcher thinks it finished, but there were -4 failed events

虽然大多数提到这个在线点他们的手指回到事件或PageViews中破坏数据库的空白,我已经证实这不是这种情况。另外,我不确定发生负面事件意味着什么(-4)!

1 个答案:

答案 0 :(得分:1)

您可以在 onPause()

中进行调度
tracker.dispatch();

以避免丢失数据,然后重新创建跟踪器