问题
I have started using Facebook SDK 3.0. I am using LoginButton widget to login into the Facebook. I am referring Scrumptious sample for doing so. In this sample, one Activity(Where session is being initialized) is hosting multiple Fragments.
But in my app, multiple activities hosting multiple fragments. First the launcher activity(Where session is being initialized) does the login operation with the LoginButton widget. How can i handle the session when I moved to other activities???
I found same kind of questions in StackOverFlow, but it has been answered for deprecated Facebook object. But i need answer with respect to LoginButton widget, UiLifecycleHelper and Session.StatusCallback.
Thanks in advance
回答1:
You must always refer to the unique Session class.
Every activity has to take an already opened session from the Session class or, if no valid sessions are found, created a new one. The method for doing this is Session.getActiveSession().
Then, in each activity, you add the callback that define the logic related to a session state change.
The UiLifecycleHelper is a very useful class that can help you manage the session state among the activities lifecycle (for example the onPause() method of this class deal with the removal of the callback added in the activity in which it's called)
来源:https://stackoverflow.com/questions/16055561/managing-facebook-session-in-android-app-throughout-multiple-activities-with-fac