如何在退出应用程序时保持栏搜索栏,然后再次保持其先前的状态。是否有人拥有此功能的代码?我在哪里可以添加代码?非常感谢你。这是我的代码:
seekBarP.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int timeRunP, boolean fromUser) {
progress = timeRunP;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
textViewP.setText("Index : " + progress + "/" + seekBarP.getMax());
}
});
btnOK.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
if (btnOK.isChecked()) {
SharedPreferences pre1 = getSharedPreferences("SavingPreferences", MODE_PRIVATE);
final int values = pre1.getInt("key", 0);
final int values1 = pre1.getInt("key1", 0);
if (values == 0 && values1 == 0) {
Processing();
long[] run = {0, seekBarS.getProgress(), seekBarP.getProgress()};
vibrator.vibrate(run, 0);
ShowNotification();
} else {
textViewS.setText("Index: " + values + "/" + seekBarS.getMax() + "(s)");
textViewP.setText("Index: " + values1 + "/" + seekBarP.getMax() + "(s)");
long[] run = {0, values, values1};
vibrator.vibrate(run, 0);
ShowNotification();
}
SharedPreferences pre = getSharedPreferences("SavingPreferences", MODE_PRIVATE);
SharedPreferences.Editor editor = pre.edit();
editor.putInt("key", seekBarS.getProgress());
editor.putInt("key1", seekBarP.getProgress());
editor.commit();
} else {
long[] off = {0, 0, 100};
vibrator.vibrate(off, 0);
CancelNotification();
moveTaskToBack(true);
}
}
});
答案 0 :(得分:1)
保存
获得的当前进度(int)seekBarP.getProgress(),进入共享首选项对象。
然后在onCreate中检查共享首选项的值,并在初始化搜索栏时调用seekBarP.setProgress(savedValue)。
如果您需要更多信息,我必须在以后工作:)