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

发布于 2024-09-10 05:12:50 字数 6026 浏览 10 评论 0原文

我正在使用 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)

--编辑-- 起初我确信这与我放置跟踪器有关,将其放入 onResume、Threads 等中,神奇地使其抛出异常。事实证明,Google 自己的示例代码(也可在其 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)

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

- 编辑 - 更奇怪的是,这似乎也导致了以下问题:

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

虽然大多数在线提及的人都将矛头指向事件或页面视图中的空白,这些空白破坏了数据库,但我已经确认情况并非如此。另外,我不确定发生负面事件(-4)意味着什么!

I am using Google Analytics for Android to track events, page views on an Android app. When calling the tracker's dispatch method, I receive a 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--
At first I was convinced it had to do with my placement of tracker, putting it in onResume, Threads, etc. magically made it throw exceptions. Turns out, Google's own example code (also available in their SDK download) also throws this Exception:

>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)

This happens when you force the original activity to be destroyed (i.e. changing orientation, going to Home screen, etc.) . I can't store the original tracker object via onSavedInstance, since tracker isn't a Parcelable. Any other ideas, clues how to get rid of this error?

--EDIT--
Even stranger, it seems that this is also causing the following problem:

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

While most mentions of this online point their fingers back to whitespaces in the Events or PageViews which corrupt the db, I have confirmed this not to be the case. Also, I'm not sure what it means to have a negative event (-4)!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夢归不見 2024-09-17 05:12:50

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

tracker.dispatch();

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

You could do a dispatch in onPause()

tracker.dispatch();

to avoid losing data and then recreate the tracker

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文