当活动存在时,系统不会自动显示活动KEY_INTENT
。由您决定是否开始该活动。
这是一些示例代码:
private AccountManagerCallback<Bundle> mAccountManagerCallback = new AccountManagerCallback<Bundle>() {
public void run(AccountManagerFuture<Bundle> future) {
Bundle bundle;
try {
bundle = future.getResult();
//if an intent was sent, start the required activity
if (bundle.containsKey(AccountManager.KEY_INTENT)) {
Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT);
//clear the new task flag just in case, since a result is expected
int flags = intent.getFlags();
flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
intent.setFlags(flags);
startActivityForResult(intent, REQUEST_CODE_AUTH);
} else {
//otherwise, just get the credentials
if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN);
String userMail = bundle.getString(AccountManager.KEY_ACCOUNT_NAME);
//use the credentials
}
}
}
catch(...) {
...
//handle errors, maybe retry your getAuthToken() call
}
}
}
我希望这是您正在寻找的,但如果我没有正确理解您的问题,请澄清。
干杯!