繁体   English   中英

AsyncTask doInBackground 方法未调用

[英]AsyncTask doInBackground method is not calling

我在 AsynTask 类的 doInBackground 方法中使用 cognitouserpool 代码。 但我的方法没有调用。 我试过用日志检查它。 它不工作。

异步任务

    public class AWSInitiator extends AsyncTask<Void, Void, Void> {
        private Context context;
        public AWSInitiator(Context context) {
            this.context = context;
        }
        @Override
        protected Void doInBackground(Void... voids) {
            CognitoUserPool.......
        Log.i("ACCESS_TOKEN", "Test");
        AuthenticationHandler authenticationHandler = new AuthenticationHandler() {
            Log.i("ACCESS_TOKEN", userSession.getIdToken().getJWTToken());
            ...
        }
    }

另一个类.java

public class TokenAuthenticator implements Authenticator {
    @Override
    public Request authenticate(Route route, Response response) {
        Log.i("Authenticate", "auth");
    AWSInitiator awsInitiator = new AWSInitiator(AppSetting.getInstance().getApplicationContext());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        awsInitiator.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
         awsInitiator.execute();
    }
return response.request().newBuilder()
                .header("Authorization", "Bearer " + AppSetting.getInstance().getSDKDataManager().getAccessToken())
                .build();
    }
}

但是日志没有显示。 我在编码中做错了什么吗? 在对 AWS 服务器进行 POST 调用时,我确实需要将令牌作为标头传递。 但它返回 null 因为 doInBackground() 不起作用。 就连TokenAuthenticator类中的Log也不行

您实际上并没有在 doInBackground 方法中打印日志。 当令牌获取完成时,您正尝试在回调方法中打印它。 我假设您的回调从未被调用,它实际上是在打印日志。

Log.i("ACCESS_TOKEN", userSession.getIdToken().getJWTToken());

为了验证我所说的,打印在外面添加一个新的 Log 语句,您应该会看到在控制台中打印的日志。 就像是 :

Log.i("ACCESS_TOKEN", "Test logs");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM