Google Associate Android Developer Practice Test - Questions Answers, Page 2
List of questions
Related questions
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:
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:
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:
For example, we have a BufferedReader reader, associated with the json file through InputStreamReader. To get a file data we can do this:
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. 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"?
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) ...
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) }
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) }
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) }
Question