SharedPreferences Tutorial

16,936
-1

Published on

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
16,936
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
318
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

SharedPreferences Tutorial

  1. 1. Android Application Development<br />Shared Preferences for Persistence<br />Ahsanul Karim<br />ahsanul.karim@sentinelbd.com<br />Sentinel Solutions Ltd.<br />http://www.sentinelbd.com<br />
  2. 2. Shared Preferences for Persistence<br />Android applications can store data in application preferences. <br />In this tutorial, you learn how to store persistent application data with shared preferences.<br />Preferences in Android are used to keep track of application and user preferences.<br />In any application, there are default preferences that can accessed through the <br />PreferenceManagerinstance and its related method <br />getDefaultSharedPreferences(Context)<br />With the SharedPreference instance one can retrieve the int value of the any preference <br />with the getInt(String key, intdefVal). <br />In our case, we can modify the SharedPreference instance in our case using the <br />edit() and use the putInt(String key, intnewVal) <br />
  3. 3. Shared Preferences for Persistence<br />We see an example of this:<br />We create a project:<br />We also create a layout<br />
  4. 4. Shared Preferences for Persistence<br />Here is our Activity<br />
  5. 5. Shared Preferences for Persistence<br />We read and write now:<br />
  6. 6. Shared Preferences for Persistence<br />Now we run the app:<br />For testing we set a value<br />Exit application<br />Launch the app again<br />Retrieve the value<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×