Shared Preferences provide a way to capture user preferences on the settings of a specific application or an activity. If you have a stream that takes up user preferences you can store it from the stream. Or you can also have the activity or the application as a whole have some values on its own. Preferences are typically name value pairs.
Example : If a user is working on a song download application, the application is designed in such a way that the song files are listed on the stream with the help of the preferences that has been set. The user here sets up a flag or particular value based on his/her preference. Whenever a song is downloaded from the server, we must make sure that it is downloaded from the right category.
Here a creation of shared preferences is made.
Let’s take an example of where there is a stack of 10 activities. A screen flow of activity from 1-10, where user input from first screen is taken and displayed on the 10th screen.
Broadcast receivers are system notification when we raise a point.
For example, the user has a service that does the download in the backdrop. Now, suppose there is a need to broadcast that the service has completed downloading the application. Only then broadcast receivers are used.
Coming back to shared preferences, they are the items where the user needs to house information inside the application with a unique XML file. Assuming we write a text file that is provided from framework, here we write some value in the text file and information is read back through shared preferences.
We write an XML file with the following values:
a) Key name – ‘myname’
b) Password – ‘password’
A point to note is that an MD5 encryption in the password is done and the MD5 encryption is stored as a value against the value in the XML file, which is all achieved with the use of shared preferences.
Got a question for us? Mention them in the comments section and we will get back to you.