Question: 3 . 1 SharedPreferences is a lightweight mechanism in Android used for storing small pieces of private data in the form of key - value
SharedPreferences is a lightweight mechanism in Android used for storing small pieces of private data in the form of keyvalue pairs. It is suitable for storing primitive data types such as Boolean, float, int, long, and strings. Write an Android program that stores and retrieves a users email and phone number using SharedPreferences. The application should have an GUI defined in activity.xml with two EditText fields: one for entering the email and another for the phone number. Additionally, include two buttons: one button to save the email and phone number into SharedPreferences and another button to retrieve and display the saved data using a Toast message.
In your MainActivity, create a suitable SharedPreferences object. Use the edit method to obtain a SharedPreferences. Editor instance. Store the email and phone number as keyvalue pairs using methods like putStringKey value and save the data with commit when the Sace button is clicked. When the view button is clicked, retrieve the stored email and phone number from SharedPreferences and display them using the Toast.makeText method. marks
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
