For example, our preferences.xml file was added by addPreferencesFromResource (R.xml.preferences).


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 . boolean isNotificationOn =
PreferenceManager.getDefaultSharedPreferences(getContext ()).getBoolean(
getContext().getString(

B . string.pref_notification_key),
getContext().getResources().getBoolean(
C . bool.pref_notification_default_value)
);
D . boolean isNotificationOn = PreferenceManager.getSharedPreferences(getContext ()).getBoolean(
getContext().getString(
E . string.pref_notification_default_value), getContext().getString(
F . string.pref_notification_key) );
G . boolean isNotificationOn = PreferenceManager.getSharedPreferences(getContext
()).getBoolean(
getContext().getResources().getBoolean(
H . bool.pref_notification_default_value), getContext().getString(
. string.pref_notification_key) );

Answer: A

Leave a Reply

Your email address will not be published.