
Google Developers Associate-Android-Developer Real Exam Questions and Answers FREE Updated on Sep 25, 2021
Associate-Android-Developer Ultimate Study Guide - Actual4test
NEW QUESTION 35
SharedPreferences.Editor is an interface used for modifying values in a SharedPreferences object. To mark in the editor that a preference value should be removed, which will be done in the actual preferences once commit() or apply() is called, what method in SharedPreferences.Editor should we use?
- A. remove(String key)
- B. removeAll()
- C. clear()
- D. delete(String key)
Answer: C
Explanation:
clear() method marks in the editor to remove ALL values from the preferences. Once commit is called, the only remaining preferences will be any that you have defined in this editor.
And no delete and removeAll method exists in SharedPreferences.Editor
NEW QUESTION 36
In general, you should send an AccessibilityEvent whenever the content of your custom view changes. For example, if you are implementing a custom slider bar that allows a user to select a numeric value by pressing the left or right arrows, your custom view should emit an event of type TYPE_VIEW_TEXT_CHANGED whenever the slider value changes. Which one of the following sample codes demonstrates the use of the sendAccessibilityEvent() method to report this event.
- A. @Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { boolean completed = super.dispatchPopulateAccessibilityEvent(event); CharSequence text = getText(); if (!TextUtils.isEmpty(text)) { event.getText().add(text); return true;
}
return completed;
} - B. @Override
public boolean onKeyUp (int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
currentValue--;
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
return true;
}
...
} - C. @Override
public boolean onKeyUp (int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
currentValue--;
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED);
return true;
}
...
}
Answer: B
Explanation:
Reference:
https://developer.android.com/guide/topics/ui/accessibility/custom-views
NEW QUESTION 37
If content in a PagedList updates, the PagedListAdapter object receives:
- A. only one item from PagedList that contains the updated information.
- B. a completely new PagedList that contains the updated information.
- C. one or more items from PagedList that contains the updated information.
Answer: B
Explanation:
Reference:
https://developer.android.com/topic/libraries/architecture/paging/ui
NEW QUESTION 38
RecyclerView is a subclass of ViewGroup and is a more resource-efficient way to display scrollable lists. Instead of creating a View for each item that may or may not be visible on the screen, RecyclerView:
- A. creates a limited number of list items and reuses them for visible content.
- B. creates a single list item and reuses it for visible content.
- C. creates an unlimited number of list items and never reuses them
- D. creates a single list item and never reuses it
Answer: A
Explanation:
Reference:
https://developer.android.com/guide/topics/ui/layout/recyclerview
NEW QUESTION 39
In a class extended PreferenceFragmentCompat. What method is used to inflate the given XML resource and add the preference hierarchy to the current preference hierarchy?
- A. setPreferenceScreen
- B. findPreference
- C. getPreferenceManager
- D. addPreferencesFromResource
Answer: D
NEW QUESTION 40
Content labels. What attribute to use to indicate that a View should act as a content label for another View?
- A. android:contentDescription
- B. android:labelFor
- C. android:hint
Answer: B
Explanation:
Reference:
https://support.google.com/accessibility/android/answer/7158690?hl=en
NEW QUESTION 41
With a room database. When performing queries, you'll often want your app's UI to update automatically when the data changes. Can you use a return value of type LiveData in your query method description to achieve this?
- A. No
- B. Yes
Answer: B
Explanation:
Room generates all necessary code to update the LiveData when the database is updated.
NEW QUESTION 42
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.getSharedPreferences(getContext()).getString( getContext().getString(R.string.pref_default_sort_value), getContext().getString(R.string.pref_sort_key) );
- B. String sortBy = PreferenceManager.getDefaultSharedPreferences(getContext ()).getString( getContext().getString(R.string.pref_sort_key), getContext().getString(R.string.pref_default_sort_value) )
- 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().getResources().getBoolean(R.bool.pref_default_sort_value) );
Answer: B
NEW QUESTION 43
As an example. In an Activity we have our TimerViewModel object (extended ViewModel), named mTimerViewModel. mTimerViewModel.timer method returns a LiveData<Long> value. What can be a correct way to set an observer to change UI in case if data was changed?
- A. mTimerViewModel.observe
(Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) }) - B. mTimerViewModel!!.timer.value.toString().observe
(Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) }) - C. mTimerViewModel!!.timer.observe
(this, Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) })
Answer: C
NEW QUESTION 44
The Testing Pyramid, shown in the Figure, illustrates how your app should include the three categories of tests: small, medium, and large. Medium tests are integration tests that:
- A. validate your app's behavior one class at a time.
- B. validate user journeys spanning multiple modules of your app.
- C. validate either interactions between levels of the stack within a module, or interactions between related modules.
Answer: C
NEW QUESTION 45
If you added to your build.gradle file a room.schemaLocation:
android {
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString
()]
}
}
}
}
Then, you build your app or module.
As a result you got a json file, with such path to it: app/schemas/your_app_package/db_package/DbClass/DB_VERSION.json What are the correct statements about this file? (Choose all that apply.)
- A. It's a file with Room-exported schema
- B. The JSONObject "database" in this file usually should contain such objects, like "entities", "views", "setupQueries", ets.
- C. Main JSONObject in this file usually should contain a number "formatVersion" and a JSONObject "database"
Answer: A,B,C
Explanation:
Exported schema file example:
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "d90c93040756d2b94a178d5555555555",
"entities": [
{
"tableName": "tea_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER
PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `type` TEXT, `origin` TEXT,
`steep_times` INTEGER, `Description` TEXT, `ingredients` TEXT, `cafeinLevel` TEXT, `favorite` INTEGER)",
"fields": [
{
"fieldPath": "mId",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mName",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mType",
"columnName": "type",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mOrigin",
"columnName": "origin",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mSteepTimeMs",
"columnName": "steep_times",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "mDescription",
"columnName": "Description",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mIngredients",
"columnName": "ingredients",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mCaffeineLevel",
"columnName": "cafeinLevel",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mFavorite",
"columnName": "favorite",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY
KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42,
'd90c93040756d2b94a178d5555555555')"
]
}
}
NEW QUESTION 46
Which statement is most true about layout_constraintLeft_toRightOf and layout_constraintStart_toEndOf constraints ?
- A. layout_constraintLeft_toRightOf is equal to layout_constraintStart_toEndOf in case if user choose a language that uses left-to-right (LTR) scripts, such as English or French, for their UI locale
- B. layout_constraintLeft_toRightOf is equal to layout_constraintStart_toEndOf in any case
- C. layout_constraintLeft_toRightOf is equal to layout_constraintStart_toEndOf in case if user choose a language that uses right-to-left (RTL) scripts, such as Arabic or Hebrew, for their UI locale
- D. layout_constraintLeft_toRightOf works with horizontal axes and layout_constraintStart_toEndOf works with vertical axes
Answer: A
Explanation:
Reference:
https://developer.android.com/training/basics/supporting-devices/languages
NEW QUESTION 47
When using an ImageView, ImageButton, CheckBox, or other View that conveys information graphically. What attribute to use to provide a content label for that View?
- A. android:labelFor
Explanation - B. android:hint
- C. android:contentDescription
Answer: C
Explanation:
Reference:
https://support.google.com/accessibility/android/answer/7158690?hl=en
NEW QUESTION 48
Assume that an app includes a default set of graphics and two other sets of graphics, each optimized for a different device setup:
res/drawable/
Contains default graphics. res/drawable-small-land-stylus/
Contains graphics optimized for use with a device that expects input from a stylus and has a QVGA low- density screen in landscape orientation. res/drawable-ja/ Contains graphics optimized for use with Japanese.
What happens if the app runs on a device that is configured to use Japanese and, at the same time, the device happens to be one that expects input from a stylus and has a QVGA low-density screen in landscape orientation?
- A. Android loads graphics from res/drawable-ja/
- B. Android loads graphics from res/drawable-small-land-stylus/
- C. Android loads graphics from res/drawable/
Answer: A
Explanation:
Reference:
https://developer.android.com/guide/topics/resources/localization
NEW QUESTION 49
For example, we have a BufferedReader reader, associated with the json file through InputStreamReader. To get a file data we can do this:
- A. 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()
} - B. 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()
} - C. 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: A
NEW QUESTION 50
By default, the notification's text content is truncated to fit one line. If you want your notification to be longer, for example, to create a larger text area, you can do it in this way:
- A. var builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentText("Much longer text that cannot fit one line...")
.setStyle(NotificationCompat.BigTextStyle()
.bigText("Much longer text that cannot fit one line..."))
... - B. var builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentText("Much longer text that cannot fit one line...")
.setTheme(android.R.style.Theme_LongText);
... - C. var builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentText("Much longer text that cannot fit one line...")
.setLongText("Much longer text that cannot fit one line..."))
...
Answer: A
Explanation:
Reference:
https://developer.android.com/training/notify-user/build-notification
NEW QUESTION 51
Custom duration in milliseconds as a parameter for the setDuration method is available when you are working with:
- A. for none of them
- B. for both of them
- C. Snackbar
- D. Toast
Answer: C
NEW QUESTION 52
The easiest way of adding menu items (to specify the options menu for an activity) is inflating an XML file into the Menu via MenuInflater. With menu_main.xml we can do it in this way:
- A. override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.menu_main, menu) return true
} - B. override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.menu.menu_main)
} - C. override fun onOptionsItemSelected(item: MenuItem): Boolean {
menuInflater.inflate(R.menu.menu_main, menu) return super.onOptionsItemSelected(item)
}
Answer: A
Explanation:
Reference:
https://developer.android.com/guide/topics/ui/accessibility/custom-views
NEW QUESTION 53
Select correct statements about Hardware Abstraction Layer (HAL). (Choose two.)
- A. The HAL function both as apps for users and to provide key capabilities that developers can access from their own app. For example, if your app would like to deliver an SMS message, you don't need to build that functionality yourself - you can instead invoke whichever SMS app is already installed to deliver a message to the recipient you specify
- B. The HAL consists of multiple library modules, each of which implements an interface for a specific type of hardware component, such as the camera or bluetooth module. When a framework API makes a call to access device hardware, the Android system loads the library module for that hardware component.
- C. Using a HAL, not using a Linux kernel, allows Android to take advantage of key security features and allows device manufacturers to develop hardware drivers for a well-known kernel.
- D. The HAL provides standard interfaces that expose device hardware capabilities to the higher-level Java API framework.
Answer: B,D
Explanation:
The system apps function both as apps for users and to provide key capabilities that developers can access from their own app. For example, if your app would like to deliver an SMS message, you don't need to build that functionality yourself - you can instead invoke whichever SMS app is already installed to deliver a message to the recipient you specify Using a Linux kernel allows Android to take advantage of key security features and allows device manufacturers to develop hardware drivers for a well-known kernel.
Reference:
https://developer.android.com/guide/platform
NEW QUESTION 54
If you are working with a Builder that creates a PeriodicWorkRequest to run periodically once within the flex period of every interval period. What statement is correct?
- A. The repeat interval must be lower than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval must be lower than or equal to PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.
- B. The repeat interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.
- C. The repeat interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval can be anything in relation to PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.
- D. The repeat interval must be greater than PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval must be greater than PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.
Answer: B
Explanation:
Working with WorkManager, from the 2018 Android Dev Summit
WorkManager: Beyond the basics, from the 2019 Android Dev Summit
Reference:
https://developer.android.com/reference/androidx/work/WorkManager?hl=en
NEW QUESTION 55
......
Ultimate Guide to Prepare Associate-Android-Developer Certification Exam for Google Developers: https://www.actual4test.com/Associate-Android-Developer_examcollection.html