SharedPreferences sp_name = this.getSharedPreferences("number", Context.MODE_WORLD_READABLE);
boolean flag = sp_name.edit().putInt("num", 3).commit();
if(true == flag)
Toast.makeText(this, "write the value into sharedpreferences successfully", Toast.LENGTH_LONG).show();
SharedPreferences sp = this.getSharedPreferences("number", Context.MODE_WORLD_WRITEABLE);
int number = sp.getInt("num", 0);
Toast.makeText(this, "the number is:"+number, Toast.LENGTH_LONG).show();
boolean flag_delete = sp.edit().remove("num").commit();
if(true == flag_delete)
Toast.makeText(this, "delete the key-value successfully", Toast.LENGTH_LONG).show();
SharedPreferences Android
最新推荐文章于 2024-09-14 15:55:09 发布