Android设置|(文件)配置

时间:2013-01-01 08:12:25

标签: java android android-ndk

我有以下方法在app设置中保存连接字符串,是否有任何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; }
            }   

1 个答案:

答案 0 :(得分:0)

使用共享偏好设置:

声明:

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

感谢。

相关问题