5

我正在使用适用于 Android 的 Google Analytics 来跟踪 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 等中神奇地使它抛出异常。事实证明,谷歌自己的示例代码(也可以在他们的 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)意味着什么!

4

1 回答 1

1

您可以在onPause()中进行调度

tracker.dispatch();

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

于 2011-02-10T16:21:31.533 回答