我能够从每个单一活动获取数据,但一次从两个活动调用时都无法获取数据。无法从两个不同的活动获取包数据
我有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