2010-07-12 77 views
6

我正在使用Google Analytics for Android來跟蹤Android應用上的事件,頁面查看。當調用跟蹤器的調度方法,我收到一個RuntimeException:Android的Google Analytics的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,螺紋等神奇使它拋出異常。原來,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。任何其他想法,線索如何擺脫這個錯誤?

- 編輯 - 更奇怪的是,似乎這也造成了以下問題:

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

雖然大多數提到這個網上的指向自己的手指回的事件或瀏覽量其腐敗的空格分貝,我已經證實這並非如此。另外,我不確定發生負面事件(-4)意味着什麼!

+1

我一直在使用GA在android系統,而現在沒有這個問題的跟蹤器做調度,奇怪。我在網上讀過一些關於類似問題的投訴。你有沒有試過在服務中運行它?有點矯枉過正,但如果它有幫助...爲了記錄,我派遣onPause()並沒有任何問題。我不建議在onResume()中進行調度,因爲AFAIK GA事件的時間戳可能是關閉的(時間是發送事件時發生的,而不是記錄時)。 – 2011-02-06 21:18:16

回答

1

你可以在的onPause()

tracker.dispatch(); 

,以避免數據丟失,然後重新創建

相關問題