ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 73 - Associate Android Developer discussion

Report
Export

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(R.string.pref_notification_key),getContext().getResources().getBoolean(R.bool.pref_notification_default_value) );
Answers
A.
boolean isNotificationOn = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean( getContext().getString(R.string.pref_notification_key),getContext().getResources().getBoolean(R.bool.pref_notification_default_value) );
B.
boolean isNotificationOn = PreferenceManager.getSharedPreferences(getContext()).getBoolean( getContext().getString(R.string.pref_notification_default_value), getContext().getString(R.string.pref_notification_key) );
Answers
B.
boolean isNotificationOn = PreferenceManager.getSharedPreferences(getContext()).getBoolean( getContext().getString(R.string.pref_notification_default_value), getContext().getString(R.string.pref_notification_key) );
C.
boolean isNotificationOn = PreferenceManager.getSharedPreferences(getContext()).getBoolean( getContext().getResources().getBoolean(R.bool.pref_notification_default_value), getContext().getString(R.string.pref_notification_key) );
Answers
C.
boolean isNotificationOn = PreferenceManager.getSharedPreferences(getContext()).getBoolean( getContext().getResources().getBoolean(R.bool.pref_notification_default_value), getContext().getString(R.string.pref_notification_key) );
Suggested answer: A
asked 18/09/2024
Luigi Trigilio
42 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first