Facebook android: passing facebook object between activities

我的梦境 提交于 2019-12-24 00:59:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!