private final String STORAGE = "STORAGE";
private SharedPreferences mSharedPreferences;
private SharedPreferences.Editor mEditor;
storeSeekbarProgress方法
private void storeSeekbarProgress(){
mSharedPreferences = this.getSharedPreferences(STORAGE, Context.MODE_PRIVATE);
mEditor = mSharedPreferences.edit();
mEditor.putInt("seekbarProgress", seekbar.getProgress());
mEditor.apply();
}
getSeekbarProgress方法
private int getSeekbarProgress(){
mSharedPreferences = this.getSharedPreferences(STORAGE, Context.MODE_PRIVATE);
return mSharedPreferences.getInt("seekbarProgress", 0); //return 0 if no data found
}
在onPause()
storeSeekBarProgress();
在onResume()
int progress = getSeekbarProgress();
seekbar.setProgress(progress);