首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Helpshift Android中的崩溃

Helpshift Android中的崩溃
EN

Stack Overflow用户
提问于 2015-12-02 18:01:58
回答 1查看 320关注 0票数 0

在发送第一条消息以帮助转移后,我将继续跟踪。我对android非常陌生,不知道如何调试它。而且,这次崩溃每5次发生一次,所以我不知道如何修复它。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-04 11:02:16

发生此崩溃是因为调用来自不包含关联活套的线程。为了阻止这次坠机:

  1. 创建处理程序线程。
  2. 使用上述处理程序线程的活套并创建一个寄存器处理程序。
  3. 在寄存器处理程序中进行API调用。

在你的异步任务中-

代码语言:javascript
复制
@Override
protected Void doInBackground(Void... voids) {
   HandlerThread handlerThread = new HandlerThread("register-device-token");
   handlerThread.start();
   new RegisterDeviceTokenHandler(handlerThread.getLooper(), context).post(null);
   return null;
}

你的注册设备令牌处理器-

代码语言:javascript
复制
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与我们联系

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34049800

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档