其中Context.MODE_PRIVATE是我们最常用的,只允许自己的程序访问SharedPreferences mSharedPreferences = getSharedPreferences("loginUser", Context.MODE_PRIVATE);
Editor editor = mSharedPreferences.edit();editor.putInt("user_id", 1);editor.putString("user_mobile","13811111111");editor.commit();
下面的写法,是清除sharepreference中的值:private int id;
private String numbers;
SharedPreferences sp = getSharedPreferences("loginUser", Context.MODE_PRIVATE);
//取得user_id和手机号
numbers = sp.getString("user_mobile", "");//如果取不到值就取后面的""id = sp.getInt("user_id", "");
SharedPreferences sp = getSharedPreferences("loginUser", Context.MODE_PRIVATE);
Editor editor = sp.edit();
editor.clear();
editor.commit();
联系客服