开发者

How to get Facebook Session in second activity In Android?

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开发者_JS百科 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜