Shared Preferences are used to store and retrieve data in between android activity’s  it is much helpful when data is to be used in more than one activity.

 

Initialization of a shared preference

 

Here AndroidCoding is used to store the values and the same is used in another activity to retrieve  Shared Preference can store and retrieve multiple types of data at once also, depending upon requirement we can use them i have listed out few types supported in shared preference.

 

 

 As it provides wide range of possibilities in storing data it is much helpful, and all the data is store at one place and can be used as many times as possible.

MainActivity.java

  Adding edittext, textview and button for user to input text

activity_main.xml

Now we will be creating second screen where we will fetch the shared preference value and show it with help of a text-view.

Second_Screen.java

 secondscreen.xml :

Now we will design second screen to show output

 

AndroidManifest.xml

  Adding Second_Screen.java to manifest file and no special permissions are required.

 

Output :

  sharedpreferences1

That’s it for this tutorial any queries comment below.

If you like it please like and share it.

Show Buttons
Hide Buttons
Read previous post:
Android Tutorial on Grid-View

Close