我已經在一個活動中聲明瞭兩個共享首選項。這兩個共享偏好與邏輯控制。如果如圖android - 嘗試使用鍵名清除共享首選項
if(logic == true){
// remove shared preferences of a particular keyname
SharedPreferences sharedPreferencesGiver = getSharedPreferences("editorCodeGiver", Context.MODE_PRIVATE);
//assuming that editorCodeGiver is the name of the shared preferences declared below in the else block
SharedPreferences.Editor editGiv = sharedPreferencesGiver.edit();
editGiv.clear().commit();
}else{
//dont clear shared preferences
SharedPreferences sharedPrefCodeGiver = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editorCodeGiver = sharedPrefCodeGiver.edit();
editorCodeGiver.putInt("statusCodeGiver", 202); //
editorCodeGiver.commit();
}
塊請我怎麼能清除在其他聲明的共享偏好阻止
我不想清除所有共享首選項。我想有選擇地清除 – parker
你該做什麼? –
我想清除一個共享首選項。像這裏初始化的那個>>>>> SharedPreferences.Editor editorCodeGiver = sharedPrefCodeGiver.edit(); – parker