Google ASSOCIATE-ANDROID-DEVELOPER Exam
Associate Android Developer (Page 4 )

Updated On: 9-Feb-2026

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



For example, we have a file in our raw folder app/src/main/res/raw/sample_teas.json. To get an
InputStream for reading it, from out Context context, we can do this:

  1. val input = context!!.openRawResource(R.raw.sample_teas)
  2. val input = context!!.getRawResource(R.raw.sample_teas)
  3. val input = context!!.resources.openRawResource(R.raw.sample_teas)

Answer(s): C



For example, we have a BufferedReader reader, associated with the json file through
InputStreamReader. To get a file data we can do this:

  1. var line: String?
    try {
    while (reader.readLine().also { line = it } != null) {
    builder.append(line)
    }
    val json = JSONObject(builder.toString())
    return json
    } catch (exception: IOException) {
    exception.printStackTrace()
    } catch (exception: JSONException) {
    exception.printStackTrace()
    }
  2. var line: JSONObject ?
    try {
    while (reader.readJSONObject ().also { line = it } != null) {
    builder.append(line)
    }
    val json = JSONObject(builder.toString())
    return json
    } catch (exception: IOException) {
    exception.printStackTrace()
    } catch (exception: JSONException) {
    exception.printStackTrace()
    }
  3. var line: String?
    try {
    while (reader.readLine().also { line = it } != null) {
    builder.append(line)
    }
    val json = JSONObject(builder.toString())
    return json
    } catch (exception: RuntimeException) {
    exception.printStackTrace()
    } catch (exception: ArrayIndexOutOfBoundsException) {
    exception.printStackTrace()
    }

Answer(s): A



For example, we have a file in our assets folder app/src/main/assets/sample_teas.json. To get an InputStream for reading it, from out Context context, we can try do this:

  1. val input = context!!.resources.openRawResource(R.raw.sample_teas)
  2. val input = context!!.assets.open("sample_teas.json")
  3. val input = context!!.resources.assets.open("sample_teas.json")

Answer(s): B






Post your Comments and Discuss Google ASSOCIATE-ANDROID-DEVELOPER exam prep with other Community members:

Join the ASSOCIATE-ANDROID-DEVELOPER Discussion