How to return seekBar
value from Activity B to Activity A ?
seekBar=(SeekBar)findViewById(R.id.seekBarPercentage);
save.setOnClickListener(new View.OnClickListener() //return to previous activity {
@Override
public void onClick(View v) {
Intent returnIntent=new Intent();
Project=project.getSelectedItem().toString(); //spinner value
Description=description.getText().toString(); //editText value
// seekBar value ?
returnIntent.putExtra("Project",Project);
returnIntent.putExtra("Description",Description);
setResult(Activity.RESULT_OK,returnIntent);
}
});
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
progress = progresValue;
// Toast.makeText(getApplicationContext(), "Changing seekbar's progress", Toast.LENGTH_SHORT).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Toast.makeText(getApplicationContext(), "Started tracking seekbar", Toast.LENGTH_SHORT).show();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
progressText.setText("Covered: " + progress + "/" + seekBar.getMax());
// Toast.makeText(getApplicationContext(), "Stopped tracking seekbar", Toast.LENGTH_SHORT).show();
}
});
}
int progress
outside theOnSeekBarChangeListener
.progress = seekBar.getProgress()
.returnIntent.putExtra("Description",Description);
, put theprogress
in theIntent
as an extra.Additionally to @Anindya Dutta's Answer if you want to persist the data use
SharedPreferences
Get
SharedPreferences
Read preferences:
To edit and save preferences
Shorter way to write
Additional info for SharedPreferences: JavaDoc and Android Developers Article