【发布时间】:2020-01-20 16:34:37
【问题描述】:
我在 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 也不行
【问题讨论】:
标签: java android android-asynctask