Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Properties vs Android SharedPreferences

The goal seems to be the same: to store key-value pairs. Is there a difference in concept between one and the other?

like image 340
Daniel Avatar asked Feb 17 '15 18:02

Daniel


2 Answers

As far as I can tell, Properties is a HashTable that lets you store key-value pairs on memory with the option of persisting them in XML(and other formats). I do not know where this XML would be stored in Android; you probably need to define a location.

SharedPreferences on the other hand, are guaranteed to be stored on disk space that only your app can access.

like image 68
Emmanuel Avatar answered Sep 21 '22 01:09

Emmanuel


From the docs:

The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).

If you need your key-value pairs to be persisted and you don't want to worry about implementations, I would prefer SharedPreferences.

In the case of a properties file you will new to write code to store the modified properties.

like image 33
antonio Avatar answered Sep 22 '22 01:09

antonio