我能夠從每個單一活動獲取數據,但一次從兩個活動調用時都無法獲取數據。無法從兩個不同的活動獲取包數據
我有3個活動
1.GoogleLogin 2.FacebookLogin 3.MainActivity
我有這個在我的GoogleLogin:
@Override
public void onConnected(Bundle connectionHint) {
// Reaching onConnected means we consider the user signed in.
Intent i = new Intent(getApplicationContext(),MainActivity.class);
Person currentUser = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
//Create the bundle
Bundle bundle = new Bundle();
//Add your data from getFactualResults method to bundle
bundle.putString("Google", "Logged in using Google Account");
bundle.putString("GoogleUsername", currentUser.getDisplayName());
//Add the bundle to the intent
i.putExtras(bundle);
startActivity(i);
// Indicate that the sign in process is complete.
mSignInProgress = STATE_DEFAULT;
}
我有這個在我的FacebookLogin:
if (session.isOpened()) {
// make request to the /me API
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Intent i = new Intent(FBMainActivity.this,MainActivity.class);
//Create the bundle
Bundle bundle = new Bundle();
//Add your data from getFactualResults method to bundle
bundle.putString("Facebook", "Logged in using Facebook Account");
bundle.putString("LastName", user.getLastName());
bundle.putString("FirstName", user.getFirstName());
//Add the bundle to the intent
i.putExtras(bundle);
startActivity(i);
}
}
}).executeAsync();
}
In My MainActivit y我得到他們如圖所示:
// 1. get passed intent
Intent facebookintent = getIntent();
// 2. get message value from intent
String lastName = facebookintent.getStringExtra("LastName");
String firstName = facebookintent.getStringExtra("FirstName");
// 3. get bundle from intent
Bundle facebookbundle = facebookintent.getExtras();
// 4. get status value from bundle
String facebookstatus = facebookbundle.getString("Facebook");
// 1. get passed intent
Intent googleintent = getIntent();
// 2. get message value from intent
String userName = googleintent.getStringExtra("GoogleUsername");
// 3. get bundle from intent
Bundle googlebundle = facebookintent.getExtras();
// 4. get status value from bundle
String googlestatus = googlebundle.getString("Google");
if (facebookstatus=="Logged in using Facebook Account"){
// 3. show message on textView
((TextView)findViewById(R.id.txtUser)).setText("Hello" + " " + lastName + " " + firstName);
}else if (googlestatus=="Logged in using Google Account"){
// 3. show message on textView
((TextView)findViewById(R.id.txtUser)).setText("Hello" + " " + userName);
}
我無法獲取GoogleUsername,但能夠從每個單一活動能夠調用時單獨獲取它們。
你想做什麼?你如何從同時間的另外兩項活動開始一項活動? – 2014-11-09 06:38:41
其實我想檢查用戶登錄哪個賬戶並從他的賬戶獲得他的用戶名 – coder 2014-11-09 06:39:39
你需要檢查你的包含鑰匙,'Facebook'或'Google'的包,然後從那裏獲取數據,當你登錄與其中一人,你需要檢查 – 2014-11-09 06:44:14