How can i save the config of my app without using a database??? (using simple textfile)

≯℡__Kan透↙ 提交于 2019-12-04 08:43:28
2red13

i suggest not to use a textfile but the Preference Editor.

static SharedPreferences settings;
static SharedPreferences.Editor editor;
settings = this.getPreferences(MODE_WORLD_WRITEABLE);
editor = settings.edit();
//store value
editor.putString("Preference_name_1", "1");
//get value
//eill return "0" if preference not exists, else return stored value
String val = settings.getString("Preference_name_1", "0");

Edit: you have to initialize the configEditor and after setting a value, you have to commit

editor = settings.edit();
editor.putBoolean("name",true);
editor.commit();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!