Google Associate Android Developer Exam Practice Questions (P. 3)
- Full Access (107 questions)
- Six months of Premium Access
- Access to one million comments
- Seamless ChatGPT Integration
- Ability to download PDF files
- Anki Flashcard files for revision
- No Captcha & No AdSense
- Advanced Exam Configuration
Question #11
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:
<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:
- Aval isNotificationOn = PreferenceManager.getDefaultSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_key), context!!.resources.getBoolean(R.bool.pref_notification_default_value) )
- Bval isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_default_value), context!!.getString(R.string.pref_notification_key), )
- Cval isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_notification_default_value), context!!.getString(R.string.pref_notification_key) )
Correct Answer:
A
A
send
light_mode
delete
Question #12
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:
<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:
- Aval sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key), context!!.resources.getBoolean(R.bool.pref_default_sort_value) )
- Bval sortBy = PreferenceManager.getSharedPreferences(context).getString( context!!.getString(R.string.pref_default_sort_value), context!!.getString(R.string.pref_sort_key), )
- Cval sortBy = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_default_sort_value), context!!.getString(R.string.pref_sort_key) )
- Dval sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key), context!!.getString(R.string.pref_default_sort_value) )
Correct Answer:
D
D
send
light_mode
delete
Question #13
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:
- Aval input = context!!.openRawResource(R.raw.sample_teas)
- Bval input = context!!.getRawResource(R.raw.sample_teas)
- Cval input = context!!.resources.openRawResource(R.raw.sample_teas)
Correct Answer:
C
C
send
light_mode
delete
Question #14
For example, we have a BufferedReader reader, associated with the json file through InputStreamReader. To get a file data we can do this:
- Avar 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() }
- Bvar 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() }
- Cvar 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() }
Correct Answer:
A
A
send
light_mode
delete
Question #15
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:
- Aval input = context!!.resources.openRawResource(R.raw.sample_teas)
- Bval input = context!!.assets.open("sample_teas.json")
- Cval input = context!!.resources.assets.open("sample_teas.json")
Correct Answer:
B
B
send
light_mode
delete
All Pages