Android Facebook onCompleted被调用两次
我做了以下工作:Android Facebook onCompleted被调用两次,android,facebook,Android,Facebook,我做了以下工作: @Override public 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
@Override
public 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();
}
及
及
请阅读第一个代码条款的注释:正如Facebook所建议的那样,该代码是有效的,因为如果没有它,即使我登录,在某些情况下也不会创建片段,但是使用该代码,onCompleted会被调用两次,我会得到一个异常。在第3个代码子句中查看我的日志:log.dcreating fragment-在异常发生之前,我查看了两次
你知道我错过了什么吗?
p、 我有一个主要的活动,它调用一个片段,用户可以在其中登录到facebook
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}
不要在简历中使用上述代码
活动通常先调用oncreate,然后再调用onresume.com,因此调用两次
请检查。谢谢,Facebook建议将此添加到onResume中,因为当我登录后从快捷方式打开应用程序时,这正是发生在我身上的事情。未对onCreate.UiLifecycleHelper调用任何内容来跟踪会话并触发会话状态更改侦听器。因此,uilifecycle helper.com调用的session.StatusCallback与facebook登录流相同
private void makeMeRequest(final Session session) {
Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (session == Session.getActiveSession()) {
if (user != null) {
log.d("creating fragment"); //<<<<<<<<<<<<<<<
//creating a fragment when the request is complete
.....
}
}
if (response.getError() != null) {
}
}
});
request.executeAsync();
}
Session session = Session.getActiveSession();
if (session != null && (session.isOpened() || session.isClosed())) {
onSessionStateChange(session, session.getState(), null);
}