我試圖在按下操作欄按鈕時註銷currentUser。這是我使用的代碼:調用Parse.User.logOut後currentUser不爲空
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_logout) {
ParseUser.logOutInBackground(new LogOutCallback() {
public void done(ParseException e) {
if (e == null) {
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser == null) {
Intent intent = new Intent(WelcomeActivity.this, DispatchActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
Toast.makeText(WelcomeActivity.this, "Still logged in.", Toast.LENGTH_LONG)
.show();
}
} else {
Toast.makeText(WelcomeActivity.this, "Error msg:" + e, Toast.LENGTH_LONG)
.show();
}
}
});
return true;
}
return super.onOptionsItemSelected(item);
}
的問題是,當我按下按鈕我得到的消息:Still logged in.
。這意味着ParseUser.logOut
被調用,但ParseUser.getCurrentUser()
未設置爲空。我在Logcat中沒有收到有關Parse的消息。
我之所以需要currentUser爲空,是因爲我使用這段代碼,以檢查是否有用戶緩存:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Check if there is current user info
if (ParseUser.getCurrentUser() != null) {
// Start an intent for the logged in activity
startActivity(new Intent(this, WelcomeActivity.class));
} else {
// Start and intent for the logged out activity
startActivity(new Intent(this, MainActivity.class));
}
}
爲什麼叫ParseUser.logOut
時不會ParseUser.getCurrentUser()
獲得設置爲空?我的問題還有其他解決方案嗎?
我使用Parse的版本1.10.3。
編輯: 初始化分析到項目中,我使用一個名爲ParseApplication.java
的應用程序文件。
public class ParseApplication extends Application{
@Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
Parse.initialize(this, "1IwScbCSI157HcqFWCyR3qF8pqqGfNwPDoXnjyAd", "yIyVXPLM8h7V0ISGL3IxPaIqoUisK4w26EkWzs2W");
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
}
}
的java文件被宣佈爲我AndroidManifest.xml
<application
android:name=".ParseApplication"
android:allowBackup="true"
android:icon="@mipmap/app_logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="@string/parse_app_id" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="@string/parse_client_key" />
EDIT2應用:
我做了一些研究,我的項目,發現我不小心宣佈Parse.enableLocalDatastore(this);
內的另一個.java文件。我將其從我的文件中刪除,現在它像一個魅力。這是導致我的應用崩潰的問題。
您是否啓用匿名用戶功能? –
我把它打開了,我把它關掉了,但'ParseUser.getCurrentUser()'沒有被設置爲null。只是爲了澄清,你的意思是在Parse.com的應用程序的設置? – Dridia
可能是一個匿名用戶的問題。有可能有一個緩存的匿名用戶。嘗試刪除/重新安裝應用程序,看看問題是否存在。另外,請輸入您正在使用的Parse版本。這可能是一個錯誤,應該報告 – Russell