Reputation: 297
I am new to facebook implementation in android. I am trying to implement facebook in my android application. I implemented using facebook-android-sdk in first activity. I want the same in the second activity also. Second activity facebook publish button is not working even though i already logged in the first activity and giving some error. It's working well if i login in the second activity also. I was fed up with this problem.
The same thing happening vice versa.( from second to first ) Can I work with unique session?
I want login facebook in one activity and post(publish) in anyone of other activities.
My code is as fallowing in the first activity,
mFacebook = new Facebook(); mAsyncRunner = new AsyncFacebookRunner(mFacebook);
SessionStore.restore(mFacebook, this);
SessionEvents.addAuthListener(new SampleAuthListener());
SessionEvents.addLogoutListener(new SampleLogoutListener());
mLoginButton.init(mFacebook, PERMISSIONS);
mPostButton.setOnClickListener()
{// some code to post a comment }
I written the same in 2nd activity also. Immediate Help Required Please.
Thanks and Regards,
Kiran
Upvotes: 2
Views: 3417
Reputation: 45162
Before doing a request in second activity, do yourFacebookObject.isSessionValid()
to see if session is valid.
You need to use the same Facebook
object in both activities. If you instantiate separate Facebook
object in each activity, in order to get a valid session, you would need to authorize again.
One way to share Facebook
object between activities, is to subclass Application
object and store your Facebook
object in there. There's plenty examples here on SO on how to do this, for example here.
Upvotes: 3