Как перенести значение переключателя на экран настроек

Как перенести значение переключателя, полученное в результате действия, и вставить это значение в настройки (экран настроек) Пожалуйста, помогите мне. enter image description here

Insert settings here enter image description here

ChooseGender.class Я пытаюсь это сделать, но это не работает

        class ChooseGender: AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.choose_gender)
        applySetting()
    }
private fun applySetting() {
    val sharedPref: SharedPreferences = getSharedPreferences("mypref", Context.MODE_PRIVATE)
    radioMale.setOnClickListener {
        sharedPref.getInt("GENDER",1)
        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
    }
    radioFemale.setOnClickListener {
        sharedPref.getInt("GENDER",2)
        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
    }
}

}

Preferences.xml

<PreferenceCategory
        android:title="@string/preferenceTitle2">

        <ListPreference
            android:key="GENDER"
            android:title="@string/gender"
            android:summary="%s"
            android:defaultValue="1"
            android:entries="@array/gender_entries"
            android:entryValues="@array/gender_entries_values"/>
    </PreferenceCategory>

Array preference

<resources>
    <string-array name="gender_entries">
        <item>@string/man</item>
        <item>@string/women</item>
    </string-array>
    <string-array name="gender_entries_values">
        <item>1</item>
        <item>2</item>
    </string-array>
</resources>

choose_gender.xml <androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView12">

        <RadioButton
            android:id="@+id/radioMale"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/man"
            android:textSize="20sp"/>


        <RadioButton
            android:id="@+id/radioFemale"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/women"
            android:textSize="20sp"/>
    </RadioGroup>

</androidx.constraintlayout.widget.ConstraintLayout>

Ответы (1 шт):

Автор решения: woesss

Как минимум нужно сохранить значение и в ListPreference используются значения типа String:

sharedPref.edit().putString("GENDER", "1").apply()

И PreferenceScreen использует стандартное хранилище настроек, которое нужно получать так:

val sharedPref = PreferenceManager.getDefaultSharedPreferences(this /* Activity context */)
→ Ссылка