How To Return Seekbar Value To Previous Activity?
How to return seekBar value from Activity B to Activity A ? seekBar=(SeekBar)findViewById(R.id.seekBarPercentage); save.setOnClickListener(new View.OnClickListener() //return t
Solution 1:
Additionally to @Anindya Dutta's Answer if you want to persist the data use SharedPreferences
Get SharedPreferences
SharedPreferencesprefs= getDefaultSharedPreferences(context);
Read preferences:
Stringkey = "test1_string_pref";
Stringdefault = "returned_if_not_defined";
String test1 = prefs.getString(key, default);
To edit and save preferences
SharedPreferences.Edtioreditor= prefs.edit(); //Get SharedPref Editor
editor.putString(key, "My String");
editor.commit();
Shorter way to write
prefs.edit().putString(key, "Value").commit();
Additional info for SharedPreferences: JavaDoc and Android Developers Article
Solution 2:
- Keep the
int progress
outside theOnSeekBarChangeListener
. - Retrieve current progress as
progress = seekBar.getProgress()
. - Similar to
returnIntent.putExtra("Description",Description);
, put theprogress
in theIntent
as an extra.
Post a Comment for "How To Return Seekbar Value To Previous Activity?"