节省近xamarin后,Android应用程序的字符串值 [英] save android app string value after close xamarin

查看:107
本文介绍了节省近xamarin后,Android应用程序的字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以保存字符串值的应用程序被关闭后,重新开放?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆