[英]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.
它不工作。
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());
...
}
}
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.