首页 > 代码库 > SharedPrefences的用处

SharedPrefences的用处

存储数据
SharedPreferences.Editor edit = getSharedPreferences("data", MODE_PRIVATE).edit();
edit.putString("bookname", "完美");
edit.putString("anthor", "刘红");
edit.putInt("page", 700);
edit.putInt("price", 230);
edit.apply();
读取数据
 SharedPreferences prep = getSharedPreferences("data", MODE_PRIVATE);
String bookname= prep.getString("bookname", "");
String anthor= prep.getString("anthor", "");
int page= prep.getInt("page",0);
int price=prep.getInt("price",0);

SharedPrefences的用处