Facebook UiLifeCycleHelper在多个活动中

时间:2015-04-28 04:52:22

标签: android facebook facebook-graph-api

我正在尝试在我的应用中实现facebook sdk。我有三个活动。 主要活动(适用于Facebook登录),适用于UiLifeCycleHelper。

$parent

但我还有其他两个活动StepOneActivity和StepTwoActivity,它们还需要整合facebook sdk。所以我必须在这些活动中使用相同的UiLifeCycleHelper实例。请告诉我如何在StepAneActivity和StepTwoActivity中实现uilifecyclehelper,它们是从MainActivity中以private UiLifecycleHelper uiHelper; private Session.StatusCallback statusCallback = new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, statusCallback); uiHelper.onCreate(savedInstanceState); } @Override protected void onResume() { super.onResume(); // For scenarios where the main activity is launched and user // session is not null, the session state change notification // may not be triggered. Trigger it if it's open/closed. Session session = Session.getActiveSession(); if (session != null && (session.isOpened() || session.isClosed())) { onSessionStateChange(session, session.getState(), null); } uiHelper.onResume(); } @Override protected void onPause() { super.onPause(); uiHelper.onPause(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data); } @Override protected void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); Session session = Session.getActiveSession(); Session.saveSession(session, outState); uiHelper.onSaveInstanceState(outState); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { Log.i(Consts.TAG, "Logged in..."); setCookies(); } else if (state.isClosed()) { Log.i(Consts.TAG, "Logged out..."); } } 启动的。我必须发布StepOneActivity的文本并邀请StepTwoActivity的朋友。

1 个答案:

答案 0 :(得分:0)

您可以创建一个FacebookActivity,其中包含所有需要Facebook实施的活动的父类

从父活动中,您将调用所有生命周期方法,并且所有这三个活动都从FacebookActivity延伸

这样你就必须编写一次这些生命周期方法,如果你需要另一个带有FB实现的Activity,只需从FacebookActivity扩展它

这是在Paint中创建的漂亮图表 Graph