Skip to content Skip to sidebar Skip to footer

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:

  1. Keep the int progress outside the OnSeekBarChangeListener.
  2. Retrieve current progress as progress = seekBar.getProgress().
  3. Similar to returnIntent.putExtra("Description",Description);, put the progress in the Intent as an extra.

Post a Comment for "How To Return Seekbar Value To Previous Activity?"