exam questions

Exam Associate Android Developer All Questions

View all questions & answers for the Associate Android Developer exam

Exam Associate Android Developer topic 1 question 66 discussion

Actual exam question from Google's Associate Android Developer
Question #: 66
Topic #: 1
[All Associate Android Developer Questions]

For example, our preferences.xml file was added by addPreferencesFromResource(R.xml.preferences). Our preferences.xml file contains such item:
<ListPreference
android:id="@+id/order_by"
android:key="@string/pref_sort_key"
android:title="@string/pref_sort_title"
android:summary="@string/pref_sort_summary"
android:dialogTitle="@string/pref_sort_dialog_title"
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:

  • A. String sortBy = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( getContext().getString(R.string.pref_sort_key), getContext().getResources().getBoolean(R.bool.pref_default_sort_value) );
  • B. String sortBy = PreferenceManager.getSharedPreferences(getContext()).getString( getContext().getString(R.string.pref_default_sort_value), getContext().getString(R.string.pref_sort_key) );
  • C. boolean sortBy = PreferenceManager.getSharedPreferences(getContext()).getBoolean( getContext().getResources().getBoolean(R.bool.pref_default_sort_value), getContext().getString(R.string.pref_sort_key) );
  • D. String sortBy = PreferenceManager.getDefaultSharedPreferences(getContext()).getString( getContext().getString(R.string.pref_sort_key), getContext().getString(R.string.pref_default_sort_value) )
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Currently there are no comments in this discussion, be the first to comment!
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...