ExamGecko
Home Home / Google / Associate Android Developer

Google Associate Android Developer Practice Test - Questions Answers, Page 2

Question list
Search
Search

List of questions

Search

Related questions











Question 11

Report
Export
Collapse

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:

A.
val isNotificationOn = PreferenceManager.getDefaultSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_key),context!!.resources.getBoolean(R.bool.pref_notification_default_value) )
A.
val isNotificationOn = PreferenceManager.getDefaultSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_key),context!!.resources.getBoolean(R.bool.pref_notification_default_value) )
Answers
B.
val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_default_value),context!!.getString(R.string.pref_notification_key), )
B.
val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_default_value),context!!.getString(R.string.pref_notification_key), )
Answers
C.
val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_notification_default_value), context!!.getString(R.string.pref_notification_key) )
C.
val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_notification_default_value), context!!.getString(R.string.pref_notification_key) )
Answers
Suggested answer: A
asked 18/09/2024
Jarlesi Bolivar
36 questions

Question 12

Report
Export
Collapse

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.
val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key),context!!.resources.getBoolean(R.bool.pref_default_sort_value) )
A.
val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key),context!!.resources.getBoolean(R.bool.pref_default_sort_value) )
Answers
B.
val sortBy = PreferenceManager.getSharedPreferences(context).getString( context!!.getString(R.string.pref_default_sort_value), context!!.getString(R.string.pref_sort_key), )
B.
val sortBy = PreferenceManager.getSharedPreferences(context).getString( context!!.getString(R.string.pref_default_sort_value), context!!.getString(R.string.pref_sort_key), )
Answers
C.
val sortBy = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_default_sort_value),context!!.getString(R.string.pref_sort_key) )
C.
val sortBy = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_default_sort_value),context!!.getString(R.string.pref_sort_key) )
Answers
D.
val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key), context!!.getString(R.string.pref_default_sort_value) )
D.
val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key), context!!.getString(R.string.pref_default_sort_value) )
Answers
Suggested answer: D
asked 18/09/2024
Nadja Burkart
32 questions

Question 13

Report
Export
Collapse

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:

A.
val input = context!!.openRawResource(R.raw.sample_teas)
A.
val input = context!!.openRawResource(R.raw.sample_teas)
Answers
B.
val input = context!!.getRawResource(R.raw.sample_teas)
B.
val input = context!!.getRawResource(R.raw.sample_teas)
Answers
C.
val input = context!!.resources.openRawResource(R.raw.sample_teas)
C.
val input = context!!.resources.openRawResource(R.raw.sample_teas)
Answers
Suggested answer: C
asked 18/09/2024
Brian Wilson
37 questions

Question 14

Report
Export
Collapse

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()}
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()}
Answers
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()}
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()}
Answers
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()}
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()}
Answers
Suggested answer: A
asked 18/09/2024
DIEGO MORENO
41 questions

Question 15

Report
Export
Collapse

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:

A.
val input = context!!.resources.openRawResource(R.raw.sample_teas)
A.
val input = context!!.resources.openRawResource(R.raw.sample_teas)
Answers
B.
val input = context!!.assets.open("sample_teas.json")
B.
val input = context!!.assets.open("sample_teas.json")
Answers
C.
val input = context!!.resources.assets.open("sample_teas.json")
C.
val input = context!!.resources.assets.open("sample_teas.json")
Answers
Suggested answer: B
asked 18/09/2024
Son Pham Hong
44 questions

Question 16

Report
Export
Collapse

An example. In our ViewModelFactory (that implements ViewModelProvider.Factory) we have an instance of our Repository, named mRepository. Our ViewModel has such constructor:

class MyViewModel(private val mRepository: MyRepository) : ViewModel() ...

Next, in our ViewModelFactory create ViewModel method (overriden) looks like this: override fun <T : ViewModel?> create(modelClass: Class<T>): T { return

try {

//MISSED RETURN VALUE HERE"

} catch (e: InstantiationException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: IllegalAccessException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: NoSuchMethodException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: InvocationTargetException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

}}

What should we write instead of "//MISSED RETURN VALUE HERE"?

A.
modelClass.getConstructor().newInstance(mRepository)
A.
modelClass.getConstructor().newInstance(mRepository)
Answers
B.
modelClass.getConstructor(MyRepository::class.java) .newInstance()
B.
modelClass.getConstructor(MyRepository::class.java) .newInstance()
Answers
C.
modelClass.getConstructor(MyRepository::class.java).newInstance(mRepository)
C.
modelClass.getConstructor(MyRepository::class.java).newInstance(mRepository)
Answers
Suggested answer: C
asked 18/09/2024
Giulia Alberghi
43 questions

Question 17

Report
Export
Collapse

What is demonstrated by the code below?

// RawDao.kt @Dao interface RawDao { @RawQuery fun getUserViaQuery(query: SupportSQLiteQuery?): User? }

// Usage of RawDao ...

val query =

SimpleSQLiteQuery("SELECT * FROM User WHERE id = ? LIMIT 1", arrayOf<Any>(sortBy)) val user = rawDao.getUserViaQuery(query) ...

A.
A method in a Dao annotated class as a raw query method where you can pass the query as a SupportSQLiteQuery.
A.
A method in a Dao annotated class as a raw query method where you can pass the query as a SupportSQLiteQuery.
Answers
B.
A method in a Dao annotated class as a query method.
B.
A method in a Dao annotated class as a query method.
Answers
C.
A method in a RoomDatabase class as a query method.
C.
A method in a RoomDatabase class as a query method.
Answers
Suggested answer: A
asked 18/09/2024
Tu Nguyen
40 questions

Question 18

Report
Export
Collapse

What happens when you create a DAO method and annotate it with @Insert?

Example:

@Dao

interface MyDao {

@Insert(onConflict = OnConflictStrategy.REPLACE) fun insertUsers(vararg users: User) }

A.
Room generates an implementation that inserts all parameters into the database in a single transaction.
A.
Room generates an implementation that inserts all parameters into the database in a single transaction.
Answers
B.
Room modifies a set of entities, given as parameters, in the database. It uses a query that matches against the primary key of each entity.
B.
Room modifies a set of entities, given as parameters, in the database. It uses a query that matches against the primary key of each entity.
Answers
C.
Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
C.
Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
Answers
Suggested answer: A
asked 18/09/2024
Christopher Dawe
41 questions

Question 19

Report
Export
Collapse

What do you want from Room when you create a DAO method and annotate it with @Update?

Example:

@Dao interface MyDao { @Update

fun updateUsers(vararg users: User) }

A.
Room generates an implementation that inserts all parameters into the database in a single transaction.
A.
Room generates an implementation that inserts all parameters into the database in a single transaction.
Answers
B.
Room modifies a set of entities, given as parameters, in the database. It uses a query that matches against the primary key of each entity.
B.
Room modifies a set of entities, given as parameters, in the database. It uses a query that matches against the primary key of each entity.
Answers
C.
Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
C.
Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
Answers
Suggested answer: B
asked 18/09/2024
Duc Hai
45 questions

Question 20

Report
Export
Collapse

What do you want from Room when you create a DAO method and annotate it with @Delete?

Example:

@Dao interface MyDao { @Delete

fun deleteUsers(vararg users: User) }

A.
Room generates an implementation that inserts all parameters into the database in a single transaction.
A.
Room generates an implementation that inserts all parameters into the database in a single transaction.
Answers
B.
Room modifies a set of entities, given as parameters, in the database. It uses a query that matches against the primary key of each entity.
B.
Room modifies a set of entities, given as parameters, in the database. It uses a query that matches against the primary key of each entity.
Answers
C.
Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
C.
Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
Answers
Suggested answer: C
asked 18/09/2024
Kabi Bashala
36 questions
Total 128 questions
Go to page: of 13