Open KnightBubble opened 9 years ago
通过sharedpreference读取配置文件信息,存储在data/data/package_name/pre..../***.xml 写入 public void writeSharedPre(View view){ SharedPreferences spf = getPreferences(Context.MODE_PRIVATE); Editor editor = spf.edit(); editor.putString("myName", "shibiao"); boolean flag = editor.commit(); if (flag) { Toast.makeText(this, "success", 1).show(); } else { Toast.makeText(this, "fail", 1).show(); } }
通过sharedpreference读取配置文件信息,存储在data/data/package_name/pre..../***.xml 写入
public void writeSharedPre(View view){ SharedPreferences spf = getPreferences(Context.MODE_PRIVATE); Editor editor = spf.edit(); editor.putString("myName", "shibiao"); boolean flag = editor.commit(); if (flag) { Toast.makeText(this, "success", 1).show(); } else { Toast.makeText(this, "fail", 1).show(); } }
> 读取
public void readSharedPre(View view) { SharedPreferences spf = getPreferences(Context.MODE_PRIVATE); String myName = spf.getString("myName", "it is just empty"); Toast.makeText(this, myName, 1).show(); }