For example, our preferences.xml file was added by addPreferencesFromResource(R.xml.preferences). Our preferences.xml file contains such item:
<SwitchPreference
android:id="@+id/notification"
android:key="@string/pref_notification_key"
android:title="@string/pref_notification_title"
android:summary="@string/pref_notification_summary"
android:defaultValue="@bool/pref_notification_default_value"
app:iconSpaceReserved="false"/>
In our Fragment, we can dynamically get current notification preference value in this way:
A. val isNotificationOn = PreferenceManager.getDefaultSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_key), context!!.resources.getBoolean(R.bool.pref_notification_default_value) )
B. val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_default_value), context!!.getString(R.string.pref_notification_key), )
C. val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_notification_default_value), context!!.getString(R.string.pref_notification_key) )
For example, our preferences.xml file was added by addPreferencesFromResource(R.xml.preferences). Our preferences.xml fi
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
For example, our preferences.xml file was added by addPreferencesFromResource(R.xml.preferences). Our preferences.xml fi
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!