Skip to main content

Posts

Showing posts with the label sharedpreferences

SharedPreferences: History saved but why not Favourite?

I use the following code to save words to History in my dictionary app: @Override public void onPause() { super.onPause(); saveHistoryToPreferences(); } public void saveHistoryToPreferences() { if (prefs.getBoolean("saveHistory", true) && mWordHistory != null && mWordHistory.size() >= 1) { StringBuilder sbHistory = new StringBuilder(); for (String item : mWordHistory) { sbHistory.append(item); sbHistory.append(","); } String strHistory = sbHistory.substring(0, sbHistory.length()-1); SharedPreferences.Editor editor = prefs.edit(); editor.putString("history", strHistory); editor.commit(); //Log.i(CONTENT_TAG,"history = " + strHistory); Log.i(CONTENT_TAG,"History saved!"); } } public void loadHistoryFromPreferences() { if (prefs.getBoolean("saveHistory", true)) {