2016-05-15 26 views
0

我試圖在成功註銷Facebook時添加回調方法,因爲onSuccess方法似乎只在登錄時纔會調用。我在此處的其他地方獲得了以下代碼塊:onCurrentAccessTokenChanged在從Facebook註銷期間多次調用

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

在您的生命週期中,您必須禁用並啓用此對象fbTracker。 例如,可以在您的活動暫停等時調用此方法stopTracking()... 您可以隨時重新啓動它。