可观察到的行为如下:
- 打开身份验证活动
- 使用 facebook sdk 按钮登录
- 注销(关闭会话)
- 杀死应用程序
- 打开应用
- 再次打开身份验证活动
- Facebook 自动登录用户,只需打开活动
一些代码 - 来自身份验证活动:
// Facebook callback
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
// Facebook Helper
private UiLifecycleHelper uiHelper;
...
protected void onCreate(Bundle savedInstanceState) {
...
fbAuthBtn = (LoginButton) findViewById(R.id.fbAuthButton);
fbAuthBtn.setApplicationId(getString(R.string.fb_app_id));
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
...
}
...
/**
* Facebook session state changed
*/
public void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
// Logged In
if (User.getInstance().authenticationType != UserAuthenticationMethod.FACEBOOK) {
showProgress();
FacebookAuthenticator fbAuth = new FacebookAuthenticator(this, handlerFacebook);
fbAuth.authenticate();
}
} else if (state.isClosed()) {
// Logged Out
User.getInstance().logout();
}
}
我实现注销如下:
public void logout() {
...
// Logout Facebook
Session fbSession = Session.getActiveSession();
if (fbSession != null) {
fbSession.close();
}
...
}
那么,如何使我的注销永久化?