简体   繁体   中英

Facebook for Android 3.0 Maintain session

I have a viewpager and ActionBarSherlock. In the menu of the actionbar I placed a button "Log In" that takes me to a login screen (this is the same as the one in the tutorial ). This login works fine, every time I open the app, I don't need to login again. What I want is to change this "Log in" menu item to "Log out" when the session is open. But the session is alwasy null. Not the state of the session, but the session itself . Why?

   Session session = Session.getActiveSession();
   if (session == null) {

   } else {
      publishStory();
   }

What am I missing here? Do I need some other code, or should this be enough?

Because you need to open the active session before you can write Session.getActiveSession() . And don't forget to define session outside:

Session.openActiveSession(getActivity(), true, new StatusCallback() {

                @Override
                public void call(Session session, SessionState state, Exception exception) {
                }
            });
session = Session.getActiveSession();

You can learn more about the related openActiveSession method here:

https://developers.facebook.com/docs/reference/android/current/Session

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM