java - 异步任务突然完成。调试 View 显示线程在 Threadpoolexecutor.runWorker(ThreadpoolExcutr$Worker) 行 :1094 处停止

标签 java android multithreading asynchronous

我正在尝试使用 GoogleAuthUtil.getToken 获取 Oauth token ,并使用异步任务将任务作为单独的线程运行。

LogCat 输出显示异步任务所需的参数已传递给它。(在本例中为上下文、电子邮件和范围)。

这是异步任务的代码:

public class GetUsernameTask extends AsyncTask<Void, Void, Void>{

    Activity mActivity;
    String mScope;
    String mEmail;

    GetUsernameTask(Activity activity, String Email, String Scope){

        Log.i(TAG,"Local variables are set from received arguments");

        this.mActivity = activity;
        this.mScope = Scope;
        this.mEmail = Email;
    }

    @Override
    protected Void doInBackground(Void... arg0) {

        try {                   
            Log.i(TAG,"fetchToken is called");
            String token = fetchToken();                                                            
                mToken = token;
                //Stuff to do with the token comes here - (Consider sending it to the backend;
            } catch(IOException e){

            }

            return null;
        }

LogCat 还告诉我调用了 fetchToken() 方法。这是 fetchToken() 的代码

private String fetchToken() throws IOException {

    try {                   
        Log.i(TAG,"attempts to getToken");

        return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
    } catch (UserRecoverableAuthException userRecoverableException){                    
        Log.i(TAG,"recoverable Exception Found");
        //((MainActivity) mActivity).handleException(userRecoverableException);                 
    } catch (GoogleAuthException fatalException){                   
        Log.i(TAG,"fataException found");                   
    }

    return null;
}

Debug模式打开之前的最后一条 logcat 消息来自 Log.i(TAG,"attempts to getToken");

我不知道如何从这里继续或如何在这种特殊情况下进行调试。任何关于下一步去哪里的方向都会很棒。

最佳答案

Android list 文件中缺少元数据标记。我在 list 文件中添加了以下代码

<meta-data 
            android:name = "com.google.android.gms.version"
            android:value="@integer/google_play_services_version" 
            />

在我添加了打印建议的 RuntimeException 之后指出了错误。这是我为 RuntimeException 添加的代码

catch (RuntimeException e){

                  Log.i(TAG, "RuntimeException caught");
                  e.printStackTrace();
              }

关于java - 异步任务突然完成。调试 View 显示线程在 Threadpoolexecutor.runWorker(ThreadpoolExcutr$Worker) 行 :1094 处停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24616644/

相关文章:

java - 使用wordnet在java中查找单词的词根

java - 如果空间已满,则线性对齐 View 中的项目以转到下一行

android - Android中的bin文件夹是什么?

android - 如何将列表/数组设置为 TextView

java - SWT 文件保存对话框 : how to show overwrite-confirmation

java - 将 Spring Webflow 从 1.0.6 升级到 2.3

java - Java 字符串合并排序

python - 在 Python 2.7 中,在 5 个不同的线程中调用函数并并行执行

java - 线程数组?

守护进程内的Python多处理池