Android Application Development
Shared Preferences for Persistence
a: “or: ae
EEF
ahsanul.karim@sentinelbd.com
Sentinel Solutions Ltd.
hhttp://www.sentinelbd.comShared Preferences for Persistence i”
Android applications can store data in application preferences.
In this tutorial, you learn how to store persistent application data with shared preferences.
1. Preferences in Android are used to keep track of application and user preferences.
2. Inany application, there are default preferences that can accessed through the
PreferenceManager instance and its related method
getDefaultSharedPreferences(Context)
3. With the SharedPreference instance one can retrieve the int value of the any preference
with the getint(String key, int defVal).
4. In our case, we can modify the SharedPreference instance in our case using the
edit() and use the putInt(String key, int newVal)Shared Preferences for Persistence i”
We see an example of this:
1. We create a project
2. We also create a layout
New Android Project
Cetera new AndidProjctesouce
ProjectrameSharsireterenedeme
(@ Create new projctin workspace
Create projec fom eng source
[Ure seat ocsson
Create projet fom exiting sample
Samples (Apidae
id Teast
Taget ame Vendor Pom — APL
Fy Andris AnctoidOpensourePcer «15.3
Google AP: Google 1s 3
[eZ Andicidi5 —__AndvidOpenSoucePicet 16 te
Standard Rado porn
Properties
Aoplemon name: SharsPrefrenedemo
Packagename. _combastaning dredpefdeno
[Wicreme Activey SharaPreterencemetctuty
MinsDKVation: +