android - 在Helpshift Android中崩溃

标签 android crash stack-trace helpshift

发送第一条消息至helpshift后,我正在关注堆栈。我对android非常陌生,不了解如何调试它。另外,此崩溃发生的次数是五分之一,所以我不确定如何重现它。

0   
java.lang.RuntimeException: An error occured while executing doInBackground()
1   
at android.os.AsyncTask$3.done(AsyncTask.java:300)
2   
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
3   
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
4   
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
5   
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
6   
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
7   
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
8   
at java.lang.Thread.run(Thread.java:818)
9   
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10  
at android.os.Handler.<init>(Handler.java:200)
11  
at android.os.Handler.<init>(Handler.java:114)
12  
at com.helpshift.HSApiData.updateUAToken(SourceFile:1260)
13  
at com.helpshift.Helpshift.registerDeviceToken(SourceFile:641)
14  
at notifications.GCMRegisterCheck$RegisteringHelpShiftWithToken.doInBackground(SourceFile:337)
15  
at notifications.GCMRegisterCheck$RegisteringHelpShiftWithToken.doInBackground(SourceFile:331)
16  
at android.os.AsyncTask$2.call(AsyncTask.java:288)
17  
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
18  
... 4 more
19  
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
20  
at android.os.Handler.<init>(Handler.java:200)
21  
at android.os.Handler.<init>(Handler.java:114)
22  
at com.helpshift.HSApiData.updateUAToken(SourceFile:1260)
23  
at com.helpshift.Helpshift.registerDeviceToken(SourceFile:641)
24  
at notifications.GCMRegisterCheck$RegisteringHelpShiftWithToken.doInBackground(SourceFile:337)
25  
at notifications.GCMRegisterCheck$RegisteringHelpShiftWithToken.doInBackground(SourceFile:331)
26  
at android.os.AsyncTask$2.call(AsyncTask.java:288)
27  
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
28  
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
29  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
30  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
31  
at java.lang.Thread.run(Thread.java:818)

最佳答案

发生此崩溃的原因是,该调用是从不包含相关循环程序的线程进行的。要停止此崩溃:

  • 创建一个处理程序线程。
  • 使用上述处理程序线程的循环程序并创建一个寄存器处理程序。
  • 在注册处理程序中进行API调用。

  • 在异步任务中-
    @Override
    protected Void doInBackground(Void... voids) {
       HandlerThread handlerThread = new HandlerThread("register-device-token");
       handlerThread.start();
       new RegisterDeviceTokenHandler(handlerThread.getLooper(), context).post(null);
       return null;
    }
    

    您的注册设备 token 处理程序-
    private static class RegisterDeviceTokenHandler extends Handler {
    
        private final Context context;
    
        public RegisterDeviceTokenHandler(Looper looper, Context context) {
            super(looper);
            this.context = context;
        }
    
        @Override
        public void handleMessage(Message msg) {
            Helpshift.registerDeviceToken(context, "hello");
        }
    }
    

    如有任何其他疑问,请随时通过support@helpshift.com与我们联系。

    关于android - 在Helpshift Android中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34049800/

    相关文章:

    java - 请求 Java ThreadInfo 的堆栈跟踪?

    android - 来自任务管理器的 ActivityManager.forceStopPackage()

    java.lang.RuntimeException : Unable to resume activity with java. lang.IllegalArgumentException

    visual-studio-2012 - 工具/选择工具箱项中的VS 2012崩溃

    ios - PresentViewController 在 iOS 6 上崩溃

    java - 为什么 catch 语句在这里被忽略了?

    error-handling - Clojure 中的 Stacktrace 和错误单子(monad)

    android - 错误 : String types not allowed (at 'src' with value 'splash/splash1.jpg'

    android - 不幸的是相机停止了

    jquery - Firefox + firebug,原型(prototype) + jquery.noconflict : Firefox crashes on page load