I want to save an object in sharedPreferences but I do not know how it is done. Could someone guide me with an example?
I want to save an object in sharedPreferences but I do not know how it is done. Could someone guide me with an example?
SharedPreferences work the same as a hash table, storing by key / value. These are saved in an XML file in the application folder inside the mobile device.
The Andorid API that you should use is the SharedPreferences .
Form of work:
How to save in them:
You can save Set objects from API 11
SharedPreferences preferences = getSharedpreferences("Ejemplo", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("registrado", true);
How to load them:
The second parameter indicates the default value that the field takes if the preference does not exist
SharedPreferences preferences = getSharedpreferences("Ejemplo", Context.MODE_PRIVATE);
boolean registrado = preferences.getBoolean("registrado", true);