Associate-Android-Developer Associate Android Developer

Loading demo links...

Showing 10–10 of 10 questions

Question 10 (KOTLIN only)

For example, our preferences.xml file was added by addPreferencesFromResource(R.xml.preferences). Our preferences.xml file contains such item:

android:entries="@array/sort_oder" android:entryValues="@array/sort_oder_value" android:defaultValue="@string/pref_default_sort_value" app:iconSpaceReserved="false" />

In our Fragment, we can dynamically get current notification preference value in this way:

Select an option, then click Submit answer.

  • val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key),
    context!!.resources.getBoolean(R.bool.pref_default_sort_value) )

  • val sortBy = PreferenceManager.getSharedPreferences(context).getString( context!!.getString(R.string.pref_default_sort_value), context!!.getString(R.string.pref_sort_key), )

  • val sortBy = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_default_sort_value),
    context!!.getString(R.string.pref_sort_key) )

  • val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key), context!!.getString(R.string.pref_default_sort_value) )