Key points
•
SharedPreferences
are a great way to store
small bits of data
for an app.
• User—specific app configuration data is often stored in
SharedPreferences
.
•
Preferences
are also stored in an app's default
SharedPreferences
, but they are
not to be confused with each other.
•
SharedPreferences
are not a good choice to store structured data, like various
entities, use a database for that.
•
SharedPreferences
are organized in
key—value pairs
that are ultimately written
out to a file in .xml format.
• Each app has its own
SharedPreferences
. When the app is uninstalled or the data
is deleted, these stored values are wiped away.
• You can create custom-named
SharedPreferences
files and store user's choices
in them.
Saving Data on Android
Chapter 2: Shared Preferences
raywenderlich.com
47
• To edit
SharedPreferences
, you first have to fetch its
Editor
, by calling
edit()
.
• When writing
SharedPreferences
, use
apply()
instead of
commit()
to perform
an asynchronous, thread—safe write.
Do'stlaringiz bilan baham: |