Android设置

编程入门 行业动态 更新时间:2024-10-28 20:22:59
Android设置|(文件)配置(Android Setting|( file ) Configuration)

我有以下方法来保存应用程序设置中的连接字符串,是否有任何Android文件(asp.net中的web配置)处理用户可以“读写”的信息?

public static System.String StrConnectionstring { get { if (DB._StrConnectionstring == null) { return AppSettings.GetConnectionSettings("DSN"); } return DB._StrConnectionstring; } set { DB._StrConnectionstring = value; } }

i have the following method to save connection string in app setting , is there is any android file like (web config in asp.net) which handle the information from which user can "read write"?

public static System.String StrConnectionstring { get { if (DB._StrConnectionstring == null) { return AppSettings.GetConnectionSettings("DSN"); } return DB._StrConnectionstring; } set { DB._StrConnectionstring = value; } }

最满意答案

使用共享首选项:

宣言 :

public static final String MYPREFS = "MySharedPreferenceFile"; SharedPreferences settings; SharedPreferences.Editor editor;

初始化:

settings = context.getSharedPreferences(MYPREFS, 0); editor = settings.edit();

存储值:

editor.putString("Name","test"); editor.commit();

要检索值:

settings.getString("Name",""); // here value field is for to specify default value

谢谢。

Use Shared Preferences :

Declaration :

public static final String MYPREFS = "MySharedPreferenceFile"; SharedPreferences settings; SharedPreferences.Editor editor;

Initialization :

settings = context.getSharedPreferences(MYPREFS, 0); editor = settings.edit();

To store values :

editor.putString("Name","test"); editor.commit();

To retrieve values :

settings.getString("Name",""); // here value field is for to specify default value

Thanks.

更多推荐

本文发布于:2023-04-28 00:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!