Android SharedPreferences Example — Writing and Reading Values

Ankit Suda
Android Grid
Published in
1 min readNov 14, 2017

Hello folks! In this post you’ll learn How you can Read and Write SharedPreferences. Android SharedPreferences are used to store data in Kay-Value pair. They’re mostly used to save Settings, User details etc.

SharedPreferences Modes:

SharedPreferences have different modes, like-

Let’s Code:

Step 1) Create a new Android Studio Project.

Step 2) Open activity_main.xml and modify it with below code-

Step 3) Open MainActivity.java and modify it with below code-

Step 4) Build and Test your app.

Now your app is ready to hit. The value will be same even you restart the App, but clearing it’s data will clear SharedPrefs also.

--

--

Ankit Suda
Android Grid

Ankit is self-taught Android App Programmer. He provides Android App Development Tutorials to Android Grid.