简体   繁体   English

AsyncTask doInBackground 方法未调用

[英]AsyncTask doInBackground method is not calling

I am using cognitouserpool codes inside AsynTask class's doInBackground method.我在 AsynTask 类的 doInBackground 方法中使用 cognitouserpool 代码。 But my method is not calling.但我的方法没有调用。 I have tried by checking it with a Log.我试过用日志检查它。 It is not working.它不工作。

AsyncTask异步任务

    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());
            ...
        }
    }

AnotherClass.java另一个类.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();
    }
}

But the Log is not showing.但是日志没有显示。 Am I doing anything wrong in my coding.我在编码中做错了什么吗? I exactly need the token to pass as the header while doing a POST call to AWS server.在对 AWS 服务器进行 POST 调用时,我确实需要将令牌作为标头传递。 But it returns null because doInBackground() is not working.但它返回 null 因为 doInBackground() 不起作用。 Even the Log in the TokenAuthenticator class is also not woking就连TokenAuthenticator类中的Log也不行

You are not actually printing the log inside doInBackground method.您实际上并没有在 doInBackground 方法中打印日志。 You are trying to print it in callback method when token fetch is complete.当令牌获取完成时,您正尝试在回调方法中打印它。 I'm assuming your callback was never invoked which is actually printing the logs.我假设您的回调从未被调用,它实际上是在打印日志。

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

To verify what I'm saying print add new a Log statement outside and you should see logs getting printed in console.为了验证我所说的,打印在外面添加一个新的 Log 语句,您应该会看到在控制台中打印的日志。 Something like :就像是 :

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

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

相关问题 在Android中停止AsyncTask doInBackground方法 - Stop AsyncTask doInBackground Method in Android 变量没有在AsyncTask的doInBackground方法中更新 - variable not getting updated in doInBackground method of AsyncTask 使用反射测试asyncTask中的doInBackground()方法 - Using reflection to test doInBackground() method in asyncTask 无法覆盖doInBackground方法(asyncTask) - Cannot override doInBackground-method (asyncTask) AsyncTask的doInBackground()方法中的NullPointer异常 - NullPointer Exception in AsyncTask's doInBackground() method 从doInBackground内部调用时,Listview重要异常:AsyncTask#1 - Listview FATAL EXCEPTION: AsyncTask #1 when calling from inside doInBackground 为什么调用新线程在AsyncTask的doInbackground()中不起作用? - Why calling a new thread will not work in AsyncTask's doInbackground()? 如何从doInBackground()方法返回JSONObject到AsyncTask上的onPostExecute()方法? - How to return JSONObject from doInBackground() method to onPostExecute() method on AsyncTask? 即使使用cancel方法也无法取消AsyncTask中的doInBackground进程 - Can't cancel doInBackground process in AsyncTask even using cancel method 在AsyncTask的doInBackground()方法中运行FileOutputStream操作无法成功执行 - Running FileOutputStream operations in AsyncTask's doInBackground() method does not execute successfully
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM