Free Associate Android Developer Exam Braindumps (page: 4)

Page 3 of 33

LiveData.postValue() and LiveData.setValue() methods have some differences. So if you have a following code executed in the main thread:

liveData.postValue("a");
liveData.setValue("b");

What will be the correct statement?

  1. The value "b" would be set at first and later the main thread would override it with the value "a".
  2. The value "a" would be set at first and later the main thread would override it with the value "b".
  3. The value "b" would be set at first and would not be overridden with the value "a".
  4. The value "a" would be set at first and would not be overridden with the value "b".

Answer(s): B



In our TeaViewModel class, that extends ViewModel, we have such prorerty:
val tea: LiveData<Tea>

An observer in our Activity (type of mViewModel variable in example is TeaViewModel) is set in this way:
mViewModel!!.tea.observe(this, Observer { tea: Tea? -> displayTea(tea) })

What will be a correct displayTea method definition?

  1. private fun displayTea()
  2. private fun displayTea(tea: Tea?)
  3. private fun displayTea(tea: LiveData?<Tea>)
  4. private fun displayTea(tea: LiveData?<T>)

Answer(s): B



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:

  1. val isNotificationOn = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
    context!!.getString(R.string.pref_notification_key),
    context!!.resources.getBoolean(R.bool.pref_notification_default_value)
    )
  2. val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean(
    context!!.getString(R.string.pref_notification_default_value),
    context!!.getString(R.string.pref_notification_key),
    )
  3. val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean(
    context!!.resources.getBoolean(R.bool.pref_notification_default_value),
    context!!.getString(R.string.pref_notification_key)
    )

Answer(s): A



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:

  1. val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString(
    context!!.getString(R.string.pref_sort_key),
    context!!.resources.getBoolean(R.bool.pref_default_sort_value)
    )
  2. val sortBy = PreferenceManager.getSharedPreferences(context).getString(
    context!!.getString(R.string.pref_default_sort_value),
    context!!.getString(R.string.pref_sort_key),
    )
  3. val sortBy = PreferenceManager.getSharedPreferences(context).getBoolean(
    context!!.resources.getBoolean(R.bool.pref_default_sort_value),
    context!!.getString(R.string.pref_sort_key)
    )
  4. val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString(
    context!!.getString(R.string.pref_sort_key),
    context!!.getString(R.string.pref_default_sort_value)
    )

Answer(s): D






Post your Comments and Discuss Google Associate Android Developer exam with other Community members:

Associate Android Developer Discussions & Posts