问题
I want to make an application that user will login in one activity with a button which call facebook login thing from facebook_android_sdk and I want to send a wall post in second activity which comes after user logins. I want to pass facebook object between activities. I tried serializable and parcelable, but didn't work ! Can someone guide me for this ? Thanks anyway
回答1:
Save your token and expires via SharedPerferences, then create new Facebook object in second activity, set token and expires from SharedPreferences and check validity. Thats all! Tutorial and here sample:
//facebook token and expires
SharedPreferences prefs = getApplicationContext().getSharedPreferences("facebook",
MODE_PRIVATE);
String access_token = prefs.getString("access_token", null);
long expires = prefs.getLong("access_expires", 0);
if(access_token != null) {
facebook.setAccessToken(access_token);
}
if(expires != 0) {
facebook.setAccessExpires(expires);
}
if (facebook.isSessionValid()) {
// Do your work here
}
回答2:
I recommend you to use the easyfacebookandroidsdk
I have used this api in my project it's better and easy to use.
回答3:
Use Shared preference for passing session between the activities.
bundle.putSerializable();
Session class implements Serializable
来源:https://stackoverflow.com/questions/10419499/facebook-android-passing-facebook-object-between-activities