AAD : Associate Android Developer Associate Android Developer : Part 05
-
What is demonstrated by the code below?
// RawDao.java @Dao interface RawDao { @RawQuery User getUserViaQuery(SupportSQLiteQuery query); } // Usage of RawDao ... SimpleSQLiteQuery query = new SimpleSQLiteQuery("SELECT * FROM User WHERE id = ? LIMIT 1", new Object[]{userId}); User user = rawDao.getUserViaQuery(query); ...
- A method in a Dao annotated class as a raw query method where you can pass the query as a
SupportSQLiteQuery
. - A method in a Dao annotated class as a query method.
- A method in a
RoomDatabase
class as a query method.
- A method in a Dao annotated class as a raw query method where you can pass the query as a
-
What happens when you create a DAO method and annotate it with
@Insert
?Example:
@Dao public interface MyDao { @Insert(onConflict = OnConflictStrategy.REPLACE) public void insertUsers(User... users); }
- Room generates an implementation that inserts all parameters into the database in a single transaction.
- 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.
- Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
-
What do you want from Room when you create a DAO method and annotate it with
@Update
?Example:
@Dao public interface MyDao { @Update public void updateUsers(User... users); }
- Room generates an implementation that inserts all parameters into the database in a single transaction.
- 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.
- Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
-
What do you want from Room when you create a DAO method and annotate it with
@Delete
?Example:
@Dao public interface MyDao { @Delete public void deleteUsers(User... users); }
- Room generates an implementation that inserts all parameters into the database in a single transaction.
- 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.
- Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.
-
In Android 8.0, API level 26, some APIs regarding notification behaviors were moved from Notification to NotificationChannel. For example, what should we use instead of NotificationCompat.Builder.setPriority() for Android 8.0 and higher?
-
NotificationChannel.setPriority()
-
NotificationChannel.setImportance()
-
NotificationCompat.Builder.setImportance()
Explanation:
Reference:
https://developer.android.com/training/notify-user/build-notification -
-
What method should we use with Notification.Builder to supply a PendingIntent to be sent when the notification is clicked?
- setContentInfo
- setContentIntent
- setDeleteIntent
Explanation:Reference:
https://developer.android.com/training/notify-user/build-notification -
DRAG DROP
Under the hood WorkManager uses an underlying job dispatching service based on the following criteria. You need to move services to the correct places.
Explanation:Videos:
– Working with WorkManager, from the 2018 Android Dev Summit
– WorkManager: Beyond the basics, from the 2019 Android Dev SummitReference:
https://developer.android.com/reference/androidx/work/WorkManager?hl=en -
When scheduling unique work, you must tell WorkManager what action to take when there is a conflict. You do this by passing an enum when enquing the work. For one-time work, you provide an
ExistingWorkPolicy
, which supports some options for handling the conflict. (Choose four.)- REPLACE (existing work with the new work. This option cancels the existing work)
- KEEP (existing work and ignore the new work)
- APPEND (the new work to the end of the existing work. This policy will cause your new work to be chained to the existing work, running after the existing work finishes)
- APPEND_OR_REPLACE (functions similarly to APPEND, except that it is not dependent on prerequisite work status. If the existing work is CANCELLED or FAILED, the new work still runs)
- APPEND_OR_KEEP (functions similarly to APPEND, except that it is not dependent on prerequisite work status. If the existing work is CANCELLED or FAILED, the new work still not runs)
- APPEND_AND_RUN (functions similarly to APPEND, except that it is not dependent on prerequisite work status. If the existing work is PAUSED, the new work still runs)
- DESTROY (if any work exists, the new work will be ignored)
- APPEND_OR_DESTROY (if no any work exists, the new work will be ignored)
Explanation:Videos:
– Working with WorkManager, from the 2018 Android Dev Summit
– WorkManager: Beyond the basics, from the 2019 Android Dev SummitReference:
https://developer.android.com/reference/androidx/work/WorkManager?hl=en -
If you are working with a Builder that creates a PeriodicWorkRequest to run periodically once within the flex period of every interval period. What statement is correct?
- The repeat interval must be greater than PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval must be greater than PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.
- The repeat interval must be lower than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval must be lower than or equal to PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.
- The repeat interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval can be anything in relation to PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.
- The repeat interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.
Explanation:Videos:
– Working with WorkManager, from the 2018 Android Dev Summit
– WorkManager: Beyond the basics, from the 2019 Android Dev SummitReference:
https://developer.android.com/reference/androidx/work/WorkManager?hl=en -
Custom duration in milliseconds as a parameter for the setDuration method is available when you are working with:
- Toast
- Snackbar
- for none of them
- for both of them
Explanation:Reference:
https://developer.android.com/guide/topics/ui/notifiers/toasts
https://developer.android.com/training/snackbar/action -
If constant LENGTH_INDEFINITE is used as a parameter for the setDuration method in Snackbar, what will happen?
- The Snackbar will be displayed for a short period of time.
- The Snackbar will be displayed for a long period of time.
- The Snackbar will be displayed for a very long period of time.
- The Snackbar will be displayed from the time that is shown until either it is dismissed, or another Snackbar is shown.
- The constant LENGTH_INDEFINITE is impossible parameter for the setDuration method in Snackbar
Explanation:Reference:
https://developer.android.com/reference/com/google/android/material/snackbar/BaseTransientBottomBar#LENGTH_INDEFINITE
https://developer.android.com/guide/topics/ui/notifiers/toasts
https://developer.android.com/training/snackbar/action -
What public methods are there in android.widget.Toast.Callback? (Choose two.)
- onDismissed()
- onToastHidden()
- onShown()
- onToastShown()
- onToastCancelled()
Explanation:Reference:
https://developer.android.com/guide/topics/ui/notifiers/toasts
https://developer.android.com/training/snackbar/action -
Which build options in the Build menu to choose to delete all intermediate/cached build files.
- Make Module
- Generate Signed Bundle / APK
- Rebuild Project
- Clean Project
- Make Project
Explanation:Reference:
https://developer.android.com/studio/run -
If you want get a debuggable APK that people can install without adb, in Android Studio you can:
- Select your debug variant and click Build Bundle(s) / APK(s) > Build APK(s).
- Click the Run button from toolbar
- Select your debug variant and click Analyze APK.
Explanation:
The Run button builds an APK with testOnly=”true”, which means the APK can only be installed via adb (which Android Studio uses). If you want a debuggable APK that people can install without adb, select your debug variant and click Build Bundle(s) / APK(s) > Build APK(s).
Reference:
https://developer.android.com/studio/run -
To build a debug APK, you can open a command line and navigate to the root of your project directory. To initiate a debug build, invoke the
assembleDebug
task:gradlew assembleDebug
This creates an APK named [module_name]-debug.apk in
[project_name]/[module_name]/build/outputs/apk/Select correct statements about generated file. (Choose all that apply.)
- The file is already signed with the debug key
- The file is already aligned with zipalign
- You can immediately install this file on a device.
Explanation:Reference:
https://developer.android.com/studio/run -
Building your app from the command line, if you have a “demo” product flavor, then you can build the debug version with the command:
- gradlew assembleDemoDebug
- gradlew installDemoDebug
- both variants are correct.
Explanation:
Before immediately install build on a running emulator or connected device, installDemoDebug cause an APK building.
Reference:
https://developer.android.com/studio/run -
If no any folder like
res/anim-<qualifiers>, res/drawable-<qualifiers>, res/layout-<qualifiers>, res/raw-<qualifiers>, res/xml-<qualifiers>
exist in the project. Which folders are required in the project anyway? (Choose two.)- res/anim/
- res/drawable/
- res/layout/
- res/raw/
- res/xml/
Explanation:Reference:
https://developer.android.com/guide/topics/resources/localization -
Assume that an app includes a default set of graphics and two other sets of graphics, each optimized for a different device setup:
– res/drawable/
Contains default graphics.
– res/drawable-small-land-stylus/
Contains graphics optimized for use with a device that expects input from a stylus and has a QVGA low-density screen in landscape orientation.
– res/drawable-ja/
Contains graphics optimized for use with Japanese.What happens if the app runs on a device that is configured to use Japanese and, at the same time, the device happens to be one that expects input from a stylus and has a QVGA low-density screen in landscape orientation?
- Android loads graphics from res/drawable/
- Android loads graphics from res/drawable-small-land-stylus/
- Android loads graphics from res/drawable-ja/
Explanation:Reference:
https://developer.android.com/guide/topics/resources/localization -
Assume that you have the following situation:
– The app code calls for R.string.text_a
– Three relevant resource files are available:
– res/values/strings.xml, which includes text_a in the app’s default language, in this case English.
– res/values-mcc404/strings.xml, which includes text_a in the app’s default language, in this case English.
– res/values-hi/strings.xml, which includes text_a in Hindi.
– The app is running on a device that has the following configuration:
– The SIM card is connected to a mobile network in India (MCC 404).
– The language is set to Hindi (hi).Which is the correct statement below?
- Android loads text_a from res/values/strings.xml (in English)
- Android loads text_a from res/values-mcc404/strings.xml (in English)
- Android loads text_a from res/values-hi/strings.xml (in Hindi)
Explanation:
Android loads text_a from res/values-mcc404/strings.xml (in English), even if the device is configured for Hindi. That is because in the resource-selection process, Android prefers an MCC match over a language match (as a priority Exception).
Reference:
https://developer.android.com/guide/topics/resources/localization -
What is the placeholder tag <xliff:g> used for?
- To mark text that should not be translated.
- To raise a translation priority to a higher level
- To raise a quantity of translations for the string
- To pick up and move sting translation from a different resource file
Explanation:Reference:
https://developer.android.com/guide/topics/resources/localization