Open for read, Facebook Session, already opened session异常

Open for read, Facebook Session, already opened session exception

我使用以下方法使用 Facebook sdk 登录 Facebook。我在那里添加了一个捕获以下异常的异常 try/catch 处理程序:

Exception ::::::﹕ Session: an attempt was made to open an already opened session.

如您所见,我在打开会话之前检查它是否已关闭。它通过了它,这意味着它已关闭并且可以安全打开它。即使捕获到异常。

我 运行 调试器并在下面标记的行处停止并检查 currentSession 状态并且它已关闭!!!!!

private Session openActiveSession(Activity activity, boolean allowLoginUI, List permissions, Session.StatusCallback callback) {
        Session currentSession = Session.getActiveSession();
        if (currentSession == null) {
            Session session = new Session.Builder(activity).build();
            Session.setActiveSession(session);
            currentSession = session;
        }

        if (!currentSession.isOpened() && (SessionState.CREATED_TOKEN_LOADED.equals(currentSession.getState()) || allowLoginUI)) {
            try {
                Session.OpenRequest openRequest = new Session.OpenRequest(activity).setPermissions(permissions).setCallback(callback);
                currentSession.openForRead(openRequest); // I stopped here..
            } catch (Exception e) {
                Log.d("Exception :::::: ", e.getMessage()); // and stopped here.
            }
            return currentSession;
        }
        return null;
    }

有什么解释吗?

这是否意味着还有另一个会话正在打开?如果存在,我总能获得一个活动会话,但我不明白这是怎么发生的。我总是在所有方法中检查活动会话并使用它!

Session.getActiveSession() 方法如何真正起作用?如果在之前的 activity 中初始化了另一个会话怎么办?这个方法应该可以吧?

我认为错误信息可以改进。它实际上应该说:"an attempt was made to open a session that's already open, or has already been closed".

您应该检查 currentSession.isClosed() 是否为真,如果是,则创建一个新会话。

一个会话只能打开一次。无法重新打开。