I want to store a time value and need to retrieve and edit it. How can I use SharedPreferences to do this?
I want to store a time value and need to retrieve and edit it.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To obtain shared preferences, use the following method
In your activity:
To read preferences:
To edit and save preferences
The android sdk’s sample directory contains an example of retrieving and storing shared preferences. Its located in the:
Edit==>
I noticed, it is important to write difference between
commit()andapply()here as well.commit()returntrueif value saved successfully otherwisefalse. It save values to SharedPreferences synchronously.apply()was added in 2.3 and doesn’t return any value either on success or failure. It saves values to SharedPreferences immediately but starts an asynchronous commit.More detail is here.