2016-12-07 59 views
0

我正在使用Parse SDK 1.13.1 for Android,我需要通過按鈕單擊註銷用戶。它的工作,但是當我打電話給ParseUser.getCurrentUser()它給我最後登錄的用戶而不是null。在Android中解析遷移後未註銷ParseUser currentUser的註銷功能

對於解析初始化我寫下面的代碼:

Parse.initialize(new Parse.Configuration.Builder(this).applicationId("PARSE_APPLICATIONID").clientKey("PARSE_CLIENT_KEY").server("PARSE_SERVER_URL").build()); 

對於註銷我寫下面的代碼

ParseUser.logOut(); 

,也試過

ParseUser.getCurrentUser().logOut(); 

ParseUser currentUser = ParseUser.getCurrentUser(); // this should be null but not 

但是,似乎ParseUser.getCurrentUser ();註銷後不爲空。

如何從緩存中刪除當前用戶?

請幫我解決這個問題。謝謝

回答

0

無論何時使用任何註冊或登錄方法,用戶都緩存在磁盤上。你可以把這個緩存的會話,並自動承擔用戶登錄。

ParseUser currentUser = ParseUser.getCurrentUser(); 
if (currentUser != null) { 
    // do stuff with the user 
} else { 
    // show the signup or login screen 
} 

您可以通過登錄出來清空當前用戶。

ParseUser.logOut(); 
ParseUser currentUser = ParseUser.getCurrentUser(); // this will now be null 

確保你把所有的功能正確設置和你不認證用戶再等

如果啓用自動創建用戶,註銷,然後獲取當前用戶會產生新的匿名用戶。這在默認情況下在初學者項目中,以便您可以立即開始使用用戶和ACL。下面ParseUser像

public static Task<Void> logOutInBackground() 

public static void logOutInBackground(LogOutCallback callback) 

方法:

如果[PFUser enableAutomaticUser];集你appDelegate,當前用戶將永遠不會返回nill

+0

在回購中發現一個問題,提示它可能是一個錯誤。 https://github.com/ParsePlatform/Parse-SDK-Android/issues/539 – Cliffordwh

0

請檢查以下 ParseUser.logOutInBackground();

ParseUser.logOutInBackground(new LogOutCallback) 

希望它能正常工作...

+0

感謝您的建議。我試過ParseUser.logOutInBackground(新的LogOutCallback),它給出了ParseUser.getCurrentUser()爲null。 但是在第二次獲取像ParseUser.getCurrentUser()這樣的用戶詳細信息之後,它會給出之前記錄的用戶。 – Dinesh