7

错误:CursorWrapperInner(10908):游标在没有事先关闭()的情况下完成

我一直在尝试让 facebook 代码与我的应用程序一起使用。出于某种原因,即使是样本也会出现此错误?我不知道为什么,但这是我的片段,我得到了与上述相同的错误。

代码:

package com.fragments;

public class MainDisplayFragment extends Fragment {

    private static final String TAG = "MainFragment";
    private UiLifecycleHelper uiHelper;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.main_display_fragment, container,
                false);

        uiHelper = new UiLifecycleHelper(this.getActivity(), callback);
        uiHelper.onCreate(savedInstanceState);

        // Facebook login button.
        LoginButton authButton = (LoginButton) view
                .findViewById(R.id.authButton);
        authButton.setFragment(this);
        // Set Application ID.
        authButton.setReadPermissions(Arrays.asList("user_friends",
                "user_about_me", "user_birthday", "user_likes", "user_status"));

        return view;
    }

    private void onSessionStateChange(Session session, SessionState state,
            Exception exception) {
        if (state.isOpened()) {
            Log.i(TAG, "Logged in...");
        } else if (state.isClosed()) {
            Log.i(TAG, "Logged out...");
        }
    }

    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    @Override
    public void onResume() {
        super.onResume();
        uiHelper.onResume();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);

    }

    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        uiHelper.onSaveInstanceState(outState);
    }
}
4

1 回答 1

0

我的问题的答案来自将交互转移到活动中。这样我们就可以监控我们主要活动中的会话状态。不幸的是,根据文档,它不应该是必要的,但这是我为那些有持续问题的人使用的修复程序。

代码:

// session callback status
    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {

            onSessionStateChange(session, state, exception);
        }
    };

    // on click listener for the login button
    public OnClickListener loginButtonListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            // call the handler
            onLoginButtonClick();

        }
    };

    // session callback
    public void onLoginButtonClick() {

        Session session = Session.getActiveSession();
        if (!session.isOpened() && !session.isClosed()) {
            session.openForRead(new Session.OpenRequest(this)
                    .setCallback(callback));
        } else {
            Session.openActiveSession(this, true, callback);
        }

    }

    public void intializeSession(Bundle savedInstanceState) {

        // initialize the facebook session
        Session session = Session.getActiveSession();
        if (session == null) {
            if (savedInstanceState != null) {
                session = Session.restoreSession(this, null, callback,
                        savedInstanceState);
            }
            if (session == null) {
                session = new Session(this);
            }
            Session.setActiveSession(session);
            if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
                session.openForRead(new Session.OpenRequest(this)
                        .setCallback(callback));
            }
        }

    }

    private void onSessionStateChange(Session session, SessionState state,
            Exception exception) {

        // IF the session is opened
        if (session.isOpened()) {

            //TODO YOUR INTERACTIONS HERE WHEN OPEN

        }
        // else IF there session is closed
        else if (session.isClosed()) {

            // TODO YOUR INTERACTIONS HERE WHEN CLOSED

        }
    }
于 2014-04-23T00:24:31.810 回答