Java Android设置|(文件)配置
我有以下方法在应用程序设置中保存连接字符串,是否有任何android文件(asp.net中的web配置)可以处理用户可以“读写”的信息Java Android设置|(文件)配置,java,android,android-ndk,Java,Android,Android Ndk,我有以下方法在应用程序设置中保存连接字符串,是否有任何android文件(asp.net中的web配置)可以处理用户可以“读写”的信息 使用共享首选项: 声明: public static final String MYPREFS = "MySharedPreferenceFile"; SharedPreferences settings; SharedPreferences.Editor editor; settings = context.getSharedPreferences(MYPR
使用共享首选项: 声明:
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
初始化:
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
存储值:
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
检索值:
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
谢谢。@mak有关理论解释和示例,您可以参考此链接。[ ] . 谢谢