Reputation: 11829
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?
Upvotes: 1
Views: 385
Reputation: 1670
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
Upvotes: 2