Pr.Pg Next Pg

Preferences tutorials


What is a Preference

  • Shared preferences are simply sets of data values that are stored persistently.

  • By persistence, we are talking about data that persists across application lifecycle events.

  • In other words, the application (or device, for that matter) can be started and stopped without losing the data.

  • The next time the user launches the application, that data will still be available.


Setting up the Preferences in our Application

  • We will have to create xml folder in res folder.

  • We then create new XML file in our xml folder. Change the type of resource to Preferences.

  • We then enter the following code in that file as follows





<?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="">



android:title="Edit Text"


android:summary="Enter a Text"









android:summary="This is a list to choose from"



Pr.Pg border                                              Next Pg