How to View Data Stored in Shared Preferences in Android Studio?
Shared Preferences in Android is local storage where we can save our data using a key and value pair. It is generally used to store data in users’ devices. Shared Preferences is also used for session management in Android apps where we are using login functionality. In this article, we will take a look at how we can view the data store in Shared Preferences in Android Studio.
What we are going to build in this article?
We will be building a simple application in which we will be simply saving data in shared preferences using a simple EditText field. After that, we will see this data stored in this file in Android Studio.
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
Step 3: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.
Now run your application and add some data in the edit text filed and click on the button to save data to shared preferences. You can get to see the process in the video below :
Step 4: View the data stored in shared preferences
Now inside Android studio in the right bottom corner, you will get to see the option as Device File Explorer. Click on that option you will get to see the below screen. Inside this screen Navigate to data > data folder.
Step 5: Opening the file containing shared preferences
Now inside that check for your app’s package name. Click on the package name for your application. After that click on the shared_prefs folder and inside that open the shared_prefs.xml file. Now you will get to see the data which we stored in our shared preferences from our application.