系統不會自動顯示活動時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
}
}
}
我希望這是你要找的人,但如果我沒有理解你的問題正確,請澄清。
乾杯!
如果我不**使用回調怎麼辦?我問了這個問題,因爲我想知道當認證者返回一個Intent時UI和UI是否需要做什麼。系統會自動顯示它還是必須在呼叫者中實施代碼?我開始認爲只有系統可以運行該意圖,因爲它必須以與帳戶創建者相同的UID運行。我真的很困惑 – 2012-06-08 11:38:45
[Add]我想你的第一句話是*答案:每個呼叫者必須實現所有的邏輯... – 2012-06-08 11:42:35