直接在MainActivity的onCreate方法中使用就可保存指定数据在APP缓存文件中
//SharedPreferences shp=getPreferences(Context.MODE_PRIVATE);//保存到MainActivity.xml中
SharedPreferences shp=getSharedPreferences("MY_DATA",Context.MODE_PRIVATE);//保存到MY_DATA.xml中
SharedPreferences.Editor editor=shp.edit();
editor.putInt("NUMBER",600);//写入数据KEY为NUMBER,value是600
// editor.commit();
editor.apply();
int x=shp.getInt("NUMBER",0);//获取数据(KEY,缺省值)
String TAG="mylog";
Log.d(TAG, "onCreate: "+x);
« ListView Adapter使用方法
|
使用viewmodelsavedstate保存数据»
|