How to transfer the OAuth to other Activity
-
Use the manager's account, how do I get token in another activity?
use SharedPreferences or inherit all activity from base activity:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash_screen);
this.authToken = null; this.mAccountManager = AccountManager.get(this); this.mAccountManager.getAuthTokenByFeatures(AccountUtils.ACCOUNT_TYPE, AccountUtils.AUTH_TOKEN_TYPE, null, this, null, null, new GetAuthTokenCallback(), null);
}
private class GetAuthTokenCallback implements AccountManagerCallback<Bundle> {
@Override
public void run(AccountManagerFuture<Bundle> result) {
Bundle bundle;
try {
bundle = result.getResult();
final Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
if (intent != null) {
startActivityForResult(intent, 1);
} else {
authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
final String accountName = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);AuthHelper.setLastUsedAccountName(AccountUtils.ACCOUNT_TYPE, accountName); Account account = AccountUtils.getAccount(SplashScreen.this, accountName); if (account == null) { account = new Account(accountName, AccountUtils.ACCOUNT_TYPE); mAccountManager.setAuthToken(account, AccountUtils.AUTH_TOKEN_TYPE, authToken); } } } catch(OperationCanceledException e) { finish(); } catch(Exception e) { e.printStackTrace(); } }
}
How is it right to process the expiry of the current and the change of password by the user?
-
If the token needs to be stored, it's sharedPrefernces, if you'll just transfer it to another activate after.
finish(),
use http://developer.android.com/intl/ru/training/basics/intents/result.html