0

The project is using a lot of these androidAnnotations.

I have the following XML file (notificationSettings):

 <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <PreferenceCategory
        app:title="@string/info">
        <SwitchPreferenceCompat
            app:key="info_preference"
            app:title="Change" />
    </PreferenceCategory>

<PreferenceCategory
    app:title="@string/library">
    <SwitchPreferenceCompat
        app:key="library_preference"
        app:title="Change" />
</PreferenceCategory>
</PreferenceScreen>

SettingsFragment.kt:

 import org.androidannotations.annotations.*
    import org.androidannotations.annotations.sharedpreferences.Pref

import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat

@PreferenceScreen(R.xml.settings)
@EFragment
open class SettingsFragment: PreferenceFragmentCompat(){
    override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {}

    @Pref
    protected lateinit var prefs: Prefs

   @PreferenceByKey(R.string.pref_notification_time)
   protected lateinit var notificationSettings: Preference


    @PreferenceClick(R.string.pref_notification_time)
    open fun notificationChanged() {
        setPreferencesFromResource(R.xml.notificationsettings, null)
    }    
}

How can I get the values from the settings into an activity?

B0r1
  • 400
  • 3
  • 15
  • You can expose a getter in your Fragment which returns the value from notificationSettings, and call that in the Activity. There is nothing special there. – WonderCsabo Oct 03 '19 at 16:02
  • Can you explain me your idea more in detail please? – B0r1 Oct 03 '19 at 18:53

0 Answers0