I want to save my String information with sharefPreferences in file as a key-value
Asked
Active
Viewed 97 times
-5
-
Search in google, lot's example are available for shared preference. – InnocentKiller Feb 27 '14 at 10:59
-
1Use this link for the solution http://stackoverflow.com/a/11027631/2675669 – Nambi Feb 27 '14 at 11:00
-
possible duplicate of [How to use SharedPreferences in Android to store, fetch and edit values](http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values) – Assaf Gamliel Feb 27 '14 at 11:03
-
You may follow this simple [tutorial](http://www.vogella.com/tutorials/AndroidFileBasedPersistence/article.html): – Adnan Feb 27 '14 at 11:05
1 Answers
1
To obtain shared preferences:
SharedPreferences prefs = this.getSharedPreferences(
"com.example.app", Context.MODE_PRIVATE);
To read preferences:
String dateTimeKey = "com.example.app.datetime";
// use a default value using new Date()
long l = prefs.getLong(dateTimeKey, new Date().getTime());
To edit and save preferences:
Date dt = getSomeDate();
prefs.edit().putLong(dateTimeKey, dt.getTime()).commit();
See this

Community
- 1
- 1

betteroutthanin
- 7,148
- 8
- 29
- 48
-
http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values – Jitesh Upadhyay Feb 27 '14 at 11:01