gpt4 book ai didi

android - Facebook android fragment 登录

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:27 27 4
gpt4 key购买 nike

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

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

代码:

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);
}
}

最佳答案

我的问题的答案来自于将交互移动到 Activity 中。这样我们就可以在我们的主要 Activity 中监控 session 状态。不幸的是,根据文档,它不应该是必需的,但这是我用于那些存在持续问题的修复程序。

代码:

// 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

}
}

关于android - Facebook android fragment 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19627776/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com