持久化存储(实例)
public class CalendarActivity extends Activity {
...
static final int DAY_VIEW_MODE = 0;
static final int WEEK_VIEW_MODE = 1;
private SharedPreferences mPrefs;
private int mCurrentViewMode;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences mPrefs = getSharedPreferences("MyPrefs", MODE_PRIVATE);
mCurrentViewMode = mPrefs.getInt(\"view_mode\", DAY_VIEW_MODE);
}
protected void onPause() {
super.onPause();
SharedPreferences.Editor ed = mPrefs.edit();
ed.putInt(\"view_mode\", mCurrentViewMode);
ed.apply();
}
}
暂无评论