Logout of Facebook sdk so user can relog in
我有以下 onclick 的 Facebook 登录按钮:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | fblogin.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Session session = Session.getActiveSession(); if (session == null) { Session.openActiveSession(LogIn.this, true, statusCallback); } else if (!session.isOpened()) { session.openForRead(new Session.OpenRequest( LogIn.this).setCallback(statusCallback) .setPermissions(permissions) ); } } }); |
然后在点击后退出如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | private OnClickListener OnClick_logout = new OnClickListener() { public void onClick(View v) { SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("loggedIn", false); editor.putString("email",""); editor.putString("password",""); editor.commit(); db.clearLists(); db.clearProducts(); Intent intent = new Intent(v.getContext(), Splash.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP ); v.getContext().startActivity(intent); } }; |
目前这不会注销 facebook,这意味着当用户返回登录活动并尝试单击 fblogin 按钮时没有任何反应。
我需要在我的注销 onclick 中添加什么才能真正注销 facebook,以便用户可以再次按下 fblogin 按钮并再次登录。
我已尝试添加到注销按钮:
1 | Session.getActiveSession().closeAndClearTokenInformation(); |
但是,当我返回登录屏幕并单击登录按钮时,我得到:
1 | 10-30 10:51:14.776: E/AndroidRuntime(18964): java.lang.UnsupportedOperationException: Session: an attempt was made to open an already opened session. |
尝试添加:
1 2 | Session.getActiveSession().closeAndClearTokenInformation(); Session.setActiveSession(null); |