I am using Android Shared Preference for saving some small Boolean data. Now if I use the same keyword string that passed as String Parameter to the getSharedPreferences() method to save my all boolean values like that sample code is they conflict?
I mean if I use A common String for all getSharedPreferences() method and inside them if I use different String in putBoolean() is they are saved properly? Actually whats the functionality of the String argument of getSharedPreferences()?
I used this to save values:
public void saveStatus(boolean b){
SharedPreferences preferences = getApplicationContext().getSharedPreferences("STATUS", android.content.Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("s1",b);
editor.commit();
}
they won't conflict if you use different key values like s1 s2 s3 different keyword for each boolean value other wise it will overwrite earlier value(This way will make keys unique):
why don't you pass two parameters to tackle issue like this:
public void saveStatus(String key,boolean b){
SharedPreferences preferences = getApplicationContext().getSharedPreferences("STATUS", android.content.Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(key,b);
editor.commit();
}