0

I have an Android app which in one of the activities the user check one of the radio buttons. I want to save the user's choice and use its value in another activity.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    This is pretty basic and explained in [the documentation](https://developer.android.com/guide/topics/data/data-storage.html#pref) – Gerald Schneider Nov 21 '14 at 16:44
  • Possible duplicate of [How to use SharedPreferences in Android to store, fetch and edit values](https://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values) – Sergey Emeliyanov Sep 22 '17 at 16:08

2 Answers2

1

To store

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(); 
prefs.edit().putBoolean("KEY", your_boolean).commit();

To retrieve

Boolean your_boolean = prefs.getBoolean("KEY", false);
Galax
  • 367
  • 1
  • 13
1

You can use shared preference for saving the values.

For Saving value into SharedPreferences use below code

SharedPreferences.Editor editor = getApplicationContext().getSharedPreferences(
                        "SHARED_PREF", MODE_PRIVATE).edit();
                editor.putString("radio_value", value);
                editor.commit();

For Retriving value from SharedPreferences use below code

  SharedPreferences prefs = getApplicationContext().getSharedPreferences(
            "SHARED_PREF", MODE_PRIVATE);
    String storedValue = prefs.getString("radio_value",""); 
MathanG
  • 1,195
  • 10
  • 22