0

I'm following the Facebook tutorial on how to implement the Facebook Login flow to my Android app. It works fine with UiLifecycleHelper and Session implementations:

private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback = 
    new Session.StatusCallback() {
    @Override
    public void call(Session session, 
            SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

In the onSessionStateChange i check if the state is opened and start the MainActivity, and everything works ok. My doubt here is: do i have to reimplement this code (UiLifeCycleHelper, onSessionStateChange) on every Activity of my app or not? And if not, how i can control the Facebook Session flow through the activities?

Blackecho
  • 1,226
  • 5
  • 18
  • 26

1 Answers1

0

Works for Facebook Android SDK 3.X only

You have to reimplement this code for each activity which uses Facebook SDK. Moving all Facebook-related code to a superclass can be a good solution (e.g. FacebookSdkActivity).

To get the session anywhere in your app, use Session.getActiveSession() method. For example, if you want to check if a user is connected to Facebook, you can use:

Session.getActiveSession() != null && Session.getActiveSession().isOpened();
Kirill Feoktistov
  • 1,448
  • 24
  • 28