我尝试在成功退出Facebook时添加回调方法,因为onSuccess方法似乎只在登录时被调用。我在此处的其他地方获得了以下代码块:
private AccessTokenTracker fbTracker;
...
fbTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken accessToken, AccessToken accessToken2) {
if (accessToken2 == null) {
Log.d(TAG, "User Logged Out.");
mEditor.putBoolean(PREF_KEY_FACEBOOK_LOGIN, false);
mEditor.commit();
Log.d(TAG, "fbLoginButton success");
String msg = "Facebook successfully logged out";
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
customFbLoginButton.setVisibility(View.VISIBLE);
customFbLogoutButton.setVisibility(View.GONE);
}
}
};
在logcat中我看到:
D/LoginActivity: User Logged Out.
D/LoginActivity: fbLoginButton success
D/LoginActivity: User Logged Out.
D/LoginActivity: fbLoginButton success
D/LoginActivity: User Logged Out.
D/LoginActivity: fbLoginButton success
D/LoginActivity: User Logged Out.
D/LoginActivity: fbLoginButton success
D/LoginActivity: User Logged Out.
D/LoginActivity: fbLoginButton success
D/LoginActivity: User Logged Out.
D/LoginActivity: fbLoginButton success
在这种情况下,我认为它没有造成任何伤害,但我想尝试解决它,如果可以的话。这种行为是否可以避免?
答案 0 :(得分:1)
在您的生命周期中,您必须禁用并启用此对象fbTracker。 例如,当您的活动暂停等时,可以调用此方法stopTracking()... 您可以随时重新启动它。