I'm creating a simple app where the user can change the seekbar value. make the default value as 0 and setMax as 5. Every time the app is closed and started back, seekbar value is set to 0. How can I use and set the previous seekbar value which was set before closing the app.
Here's my Activity class >
public class MainActivity extends Activity {
SeekBar s;
TextView v;
public int n;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s=(SeekBar)findViewById(R.id.seekBar1);
v=(TextView)findViewById(R.id.textView1);
next=(Button)findViewById(R.id.button1);
s.setProgress(n);
v.setText(n+" ");
s.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
n = progress;
v.setText(n+" ");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
v.setText(n+" ");
}
});
}
}
I Tried using onSaveInstanceState and onRestoreInstanceState but failed to restore back to the previous state. Please Help
Thanks in Advance.