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

Updated On: 9-Feb-2026

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”?

  1. modelClass.getConstructor()
    .newInstance(mRepository)
  2. modelClass.getConstructor(MyRepository::class.java)
    .newInstance()
  3. modelClass.getConstructor(MyRepository::class.java)
    .newInstance(mRepository)

Answer(s): C



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)
...

  1. A method in a Dao annotated class as a raw query method where you can pass the query as a
    SupportSQLiteQuery.
  2. A method in a Dao annotated class as a query method.
  3. A method in a RoomDatabase class as a query method.

Answer(s): A



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)
}

  1. Room generates an implementation that inserts all parameters into the database in a single transaction.
  2. 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.
  3. Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.

Answer(s): A



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)
}

  1. Room generates an implementation that inserts all parameters into the database in a single transaction.
  2. 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.
  3. Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.

Answer(s): B



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)
}

  1. Room generates an implementation that inserts all parameters into the database in a single transaction.
  2. 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.
  3. Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.

Answer(s): C






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

Join the ASSOCIATE-ANDROID-DEVELOPER Discussion