How to Use SharedPreferences to store, read, and edit values in Android, sharedpreferences
I need to store a Time Value and retrieve and edit it. Does anyone know? How to Use
SharedPreferences complete
Solution
For android shared preferences, you can add the following code to your activity.
SharedPreferences prefs = this. getSharedPreferences ("com. example. app", Context. MODE_PRIVATE );
Read preferences as follows:
String dateTimeKey = "com. example. app. datetime ";
// Use a default value using new Date ()
Long l = prefs. getLong (dateTimeKey, new Date (). getTime ());
Edit and save preferences as follows:
Date dt = getSomeDate ();
Prefs. edit (). putLong (dateTimeKey, dt. getTime (). apply ();
The example directory in the Android SDK contains examples of retrieval and storage sharing. The location is as follows:
<Android-sdk-home>/samples/android-<platformversion>/ApiDemos directory
Address: http://www.itmmd.com/201410/35.html
This article is organized and published by Meng IT personnel. The reprinted article must indicate the source.