1

There is a way to save string value after the app is closed and re open?

I thinking something like Sqlite but i want to know if there is something easier.

Thanks.

Khan
  • 344
  • 1
  • 7
  • 21
kipo
  • 63
  • 1
  • 1
  • 6

2 Answers2

1

use shared preferences. shared preferences is a mechanism for saving key value pair of data like the string you have!

use this youtube playlist to learn how to use shared preferences. http://goo.gl/DAnQqr

Alireza Ahmadi
  • 5,122
  • 7
  • 40
  • 67
1

An easier way to do this for a small amount of settings is to use Android's Shared Preferences functionality. It is simpler to code than implementing a full SQLite database.

In Android, it is called SharedPreferences. You can use that to find many Android java examples which you can port across to Xamarin.

In Xamarin.Android C#, that same functionality comes for the interface ISharedPreferences, which maps to the SharedPreferences java class.


For example, to save your string using C#, you could write something like:

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (mContext);
prefs.Edit ().PutString ("key_for_my_string_value", mString).Commit ();

To retrieve it again, you could write something like:

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (mContext);
mString= prefs.GetString ("key_for_my_string_value");

More info on ISharedPreferences in my post here:

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255