节省近xamarin后,Android应用程序的字符串值 [英] save android app string value after close xamarin
问题描述
有一种方法可以保存字符串值的应用程序被关闭后,重新开放?
There is a way to save string value after the app is closed and re open?
我想是这样 sqlite的
,但我想知道如果有什么更容易。
I thinking something like Sqlite
but i want to know if there is something easier.
感谢。
推荐答案
这是更简单的方式来将设置少量做,这是使用Android的共享preferences功能。这比实现一个完整的SQLite数据库简单code。
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.
在Android中,它被称为共享preferences
。你可以用它来发现许多Android的Java例子,你可以跨端口到Xamarin。
In Android, it is called SharedPreferences
. You can use that to find many Android java examples which you can port across to Xamarin.
在 Xamarin.Android C#,同样的功能来为接口 IShared preferences
,它映射到共享preferences Java类。
In Xamarin.Android C#, that same functionality comes for the interface ISharedPreferences
, which maps to the SharedPreferences java class.
例如,使用C#,以节省您的字符串,你可以写这样的:
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");
在 IShared preferences
在我的岗位在此处了解详情:
More info on ISharedPreferences
in my post here:
- How do I use SharedPreferences in Xamarin.Android?
这篇关于节省近xamarin后,Android应用程序的字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!