ExamGecko
Home Home / Google / Associate Android Developer

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

Question list
Search
Search

List of questions

Search

Related questions











SharedPreferences.Editor is an interface used for modifying values in a SharedPreferences object. All changes you make in an editor are batched, and not copied back to the original SharedPreferences until you call:

A.
commit()
A.
commit()
Answers
B.
apply()
B.
apply()
Answers
C.
commit() or apply()
C.
commit() or apply()
Answers
Suggested answer: C

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.
delete(String key)
A.
delete(String key)
Answers
B.
clear()
B.
clear()
Answers
C.
remove(String key)
C.
remove(String key)
Answers
D.
removeAll()
D.
removeAll()
Answers
Suggested answer: B

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

What is the incorrect statement about Data Access Object (androidx.room.Dao)?

A.
Data Access Objects are the main classes where you define your database interactions. They can include a variety of query methods.
A.
Data Access Objects are the main classes where you define your database interactions. They can include a variety of query methods.
Answers
B.
The class marked with @Dao should either be an interface or an abstract class. At compile time, Room will generate an implementation of this class when it is referenced by a Database.
B.
The class marked with @Dao should either be an interface or an abstract class. At compile time, Room will generate an implementation of this class when it is referenced by a Database.
Answers
C.
An abstract @Dao class can optionally have a constructor that takes a Database as its only parameter.
C.
An abstract @Dao class can optionally have a constructor that takes a Database as its only parameter.
Answers
D.
It is recommended to have only one Dao class in your codebase for all tables.
D.
It is recommended to have only one Dao class in your codebase for all tables.
Answers
Suggested answer: D

By adding a RoomDatabase.Callback to the room database builder RoomDatabase.Builder (method addCallback(RoomDatabase.Callback callback)), we can: (Choose two.)

A.
set the database factory
A.
set the database factory
Answers
B.
handle database first time creation
B.
handle database first time creation
Answers
C.
handle database opening
C.
handle database opening
Answers
D.
disable the main thread query check for Room
D.
disable the main thread query check for Room
Answers
Suggested answer: B, C

By executing an allowMainThreadQueries() method to the room database builder RoomDatabase.Builder, we can:

A.
set the database factory
A.
set the database factory
Answers
B.
handle database first time creation
B.
handle database first time creation
Answers
C.
handle database opening
C.
handle database opening
Answers
D.
disable the main thread query check for Room
D.
disable the main thread query check for Room
Answers
Suggested answer: D

Room can export your database's schema information into a JSON file at compile time. What annotation processor property you should set in your app/build.gradle file to export the schema?

A.
room.expandProjection
A.
room.expandProjection
Answers
B.
room.incremental
B.
room.incremental
Answers
C.
room.schemaLocation
C.
room.schemaLocation
Answers
Suggested answer: C

Explanation:

android {

...

defaultConfig {

... javaCompileOptions { annotationProcessorOptions { arguments += ["room.schemaLocation": "$projectDir/

schemas".toString()]

}

}

}}

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
A.
It's a file with Room-exported schema
Answers
B.
Main JSONObject in this file usually should contain a number "formatVersion" and a JSONObject "database"
B.
Main JSONObject in this file usually should contain a number "formatVersion" and a JSONObject "database"
Answers
C.
The JSONObject "database" in this file usually should contain such objects, like "entities", "views", "setupQueries", ets.
C.
The JSONObject "database" in this file usually should contain such objects, like "entities", "views", "setupQueries", ets.
Answers
Suggested 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')"

]

}

}

Select 3 major components of the Room. (Choose three.)

A.
@Entity
A.
@Entity
Answers
B.
@Query
B.
@Query
Answers
C.
@RawQuery
C.
@RawQuery
Answers
D.
@DAO
D.
@DAO
Answers
E.
@WorkerThread
E.
@WorkerThread
Answers
F.
@Database
F.
@Database
Answers
Suggested answer: A, D, F

A class that you create for managing multiple data sources. In addition to a Room database, this class could manage remote data sources such as a web server. It is about:

A.
Activity/Fragment
A.
Activity/Fragment
Answers
B.
ViewModel
B.
ViewModel
Answers
C.
Repository
C.
Repository
Answers
D.
Room database
D.
Room database
Answers
Suggested answer: C

@Query is the main annotation used in DAO classes. It allows you to perform read/write operations on a database. Each @Query method is verified at compile time, so what happens if there is a problem with the query?

A.
a runtime error occurs instead of a compilation failure.
A.
a runtime error occurs instead of a compilation failure.
Answers
B.
a compilation error occurs instead of a runtime failure.
B.
a compilation error occurs instead of a runtime failure.
Answers
C.
both compilation error and runtime failure occurs.
C.
both compilation error and runtime failure occurs.
Answers
Suggested answer: B
Total 128 questions
Go to page: of 13