Skip to content Skip to sidebar Skip to footer

Accountmanager Blockinggetauthtoken Gets Stuck

I've been using the SampleSyncAdapter as a base to create my own SyncAdapter. It seems to work well to add a new account, but once I want to get the authtoken with AccountManager.b

Solution 1:

The blockingGetAuthToken method is a helper that calls getAuthToken synchronously.

If you are accessing the network to retrieve the auth token you will be blocked until the request succeeds. You should check that you can access the network resource properly from within your application.

Solution 2:

originally method is a convenient way to get authtoken instead calling method getAuthToken. have to make sure not in the mainthread by calling methed runOnUIthread. or you can call the default method getAuthToken and using callback for execute next instruction. for the example.

final AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(account, AccountConfig.AUTHTOKEN_TYPE, null, this, null, null);
    newThread(newRunnable() {
        @Overridepublicvoidrun() {
            try {

                Bundlebnd= future.getResult();
                finalStringauthtoken= bnd.getString(AccountManager.KEY_AUTHTOKEN); 
                if (authtoken == null) { 
                    return;
                }
                 // this callback interface method 
                logoutCallback.onLogoutFinished(authtoken);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();

Post a Comment for "Accountmanager Blockinggetauthtoken Gets Stuck"