I am creating a new Android app using SyncAdapter to handle db sync.
I have everything in place and the app is working fine but I noticed that I am logged in twice.
The first login takes place when the AuthenticatorActivity class (it extends AccountAuthenticatorActivity) validates the user and password.
If the user and password are correct the AuthenticatorActivity then does:
- If the
accountdidn't exist it creates it usingmAccountManager.addAccountExplicitly() - The
authTokenis saved usingintent.putExtra(AccountManager.KEY_AUTHTOKEN, authToken);
This was basically copied/pasted from the Android samples, so I guess it's ok.
The issue is that when the SyncAdapter launches and uses
authtoken = mAccountManager.blockingGetAuthToken(account,
AuthenticatorActivity.PARAM_AUTHTOKEN_TYPE, true);
The getAuthToken() method inside the Authenticator class which extends AbstractAccountAuthenticator is called. And inside this method I am hitting the login endpoint once again.
From that point onwards the login endpoint is not hit again until the authToken expires.
This is not something that bothers me a lot but I would like to know if there is a way to avoid doing the login twice.