-5

I want to save my String information with sharefPreferences in file as a key-value

Adnan
  • 5,025
  • 5
  • 25
  • 44
Ruben JG
  • 97
  • 7
  • Search in google, lot's example are available for shared preference. – InnocentKiller Feb 27 '14 at 10:59
  • 1
    Use 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 Answers1

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