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:
An example. In our ViewModelFactory (that implements ViewModelProvider.Factory) we have an instance of our Repository, named mRepository. OurViewModel 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"?
What is demonstrated by the code below?// RawDao.kt@Daointerface RawDao {@RawQueryfun 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)...
What happens when you create a DAO method and annotate it with @Insert?Example:@Daointerface MyDao {@Insert(onConflict = OnConflictStrategy.REPLACE)fun insertUsers(vararg users: User)}
What do you want from Room when you create a DAO method and annotate it with @Update?Example:@Daointerface MyDao {@Updatefun updateUsers(vararg users: User)}
What is a correct part of an Implicit Intent for sharing data implementation?