简体   繁体   English

使用Facebook SDK 3在多个活动中管理Android应用程序中的Facebook会话

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

I have started using Facebook SDK 3.0. 我已经开始使用Facebook SDK 3.0了。 I am using LoginButton widget to login into the Facebook. 我正在使用LoginButton小部件登录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. 首先,启动器活动(正在初始化会话)使用LoginButton小部件执行登录操作。 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 . 我在StackOverFlow中发现了同样的问题,但已经对已弃用的Facebook对象进行了回答。 But i need answer with respect to LoginButton widget, UiLifecycleHelper and Session.StatusCallback . 我需要回答一下LoginButton小部件,UiLifecycleHelper和Session.StatusCallback

Thanks in advance 提前致谢

You must always refer to the unique Session class. 您必须始终引用唯一的Session类。 Every activity has to take an already opened session from the Session class or, if no valid sessions are found, created a new one. 每个活动都必须从Session类中获取已打开的会话,或者,如果找不到有效会话,则创建一个新会话。 The method for doing this is Session.getActiveSession() . 执行此操作的方法是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) UiLifecycleHelper是一个非常有用的类,可以帮助您管理活动生命周期中的会话状态(例如,此类的onPause()方法处理删除在其调用的活动中添加的回调)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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