簡體   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