Managing Facebook Session in Android App throughout multiple activities with Facebook SDK 3

给你一囗甜甜゛ 提交于 2019-12-01 07:45:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!