## Android #### Q1. To add features, components, and permissions to your Android app, which file needs to be edited? - [x] AndroidManifest.xml - [ ] Components.xml - [ ] AppManifest.xml - [ ] ComponentManifest.xml #### Q2. Which XML attribute should be used to make an Image View accessible? - [ ] android:talkBack - [ ] android:labelFor - [ ] android:hint - [x] android:contentDescription #### Q3. You launch your app, and when you navigate to a new screen it crashes, Which action will NOT help you diagnose the issue? - [ ] Set breakpoints and then step through the code line by line - [ ] Use the profiler tools in Android Studio to detect anomalies in CPU and network usage. - [x] Add a Thread.sleep() call before you start the new activity. - [ ] inspect the logs in Logcat. #### Q4. Why might push notifications stop working? - [x] all of these answers - [ ] The device token is not being sent to push the provider correctly. - [ ] Google Play Services is not installed on the device/emulator. - [ ] Battery optimization is turned on on the device. #### Q5. What is the correct set of component classes needed to implement a RecyclerView of items that displays a list of widgets vertically? - [ ] A ```java RecycleView RecyclerView.Adapter RecyclerView.ViewHolder LinearLayoutManager ``` - [ ] B ```java RecycleView RecyclerView.Adapter RecyclerView.ViewHolder LinearLayoutManager ``` - [ ] C ```java RecycleView RecyclerView.Adapter RecyclerView.ViewHolder LinearLayoutManager ``` - [x] D ```java RecycleView RecyclerView.Adapter RecyclerView.ViewHolder LinearLayoutManager ``` #### Q6. The Android system kills the process when it needs to free up memory. The likelihood of the system killing a given process depends on the state of the process and the activity at the time. With a combination of process and activity state is most likely to be killed? - [x] Process:In the background;Activity:Is stopped - [ ] Process:In the background;Activity:Is paused - [ ] Process:In the foreground;Activity:Is started - [ ] Process:In the foreground;Activity:Is paused #### Q7. You have created a NextActivity class that relies on a string containing some data that passes inside the intent Which code snippet allows you to launch your activity? - [ ] A ```java Intent(this, NextActivity::class.java).also { intent -> startActivity(intent) } ``` - [ ] B ```java Intent(this, NextActivity::class.java).apply { put(EXTRA_NEXT, "some data") }.also { intent -> activityStart(intent) } ``` - [x] C ```java Intent(this, NextActivity::class.java).apply { putExtra(EXTRA_NEXT, "some data") }.also { intent -> startActivity(intent) } ``` - [ ] D ```java Intent(this, NextActivity::class.java).apply { put(EXTRA_NEXT, "some data") }.also { intent -> activityStart(intent) } ``` #### Q8. You want to include about and setting modules in your project. Which files accurately reflect their inclusion? - [ ] `in build.gradle:include ':app',':about' ':settings'` - [x] `in settings.gradle:include ':app',':about' ':settings'` - [ ] `in settings.gradle:include ':about',':settings'` - [ ] `in gradle.properties:include ':app',':about' ':settings'` #### Q9. What is the benefit of using @VisibleForTesting annotation? - [x] to denote that a class, method, or field has its visibility relaxed to make code testable - [ ] to denote that a class, method, or field is visible only in the test code - [ ] to denote that a class, method, or field has its visibility increased to make code less testable - [ ] to throw a run-time error if a class, method, or field with this annotation is accessed improperly #### Q10. How would you specify in your build.gradle file that your app required at least API level 21 to run, but it can be tested on API level 28? - [ ] A ``` defaultConfig { ... minApiVersion 21 targetApiVersion 28 } ``` - [ ] B ``` defaultConfig { ... targetSdkVersion 21 testSdkVersion 28 } ``` - [ ] C ``` defaultConfig { ... minSdkVersion 21 testApiVersion 28 } ``` - [x] D ``` defaultConfig { ... minSdkVersion 21 targetSdkVersion 28 } ``` #### Q11. When will an activity's onActivityResult()be called? - [ ] when calling finish()in the parent activity - [ ] when placing an app into the background by switching to another app - [ ] When onStop() is called in the target activity - [x] when calling finish() in the target activity [Reference](https://developer.android.com/reference/android/app/Activity) #### Q12. You need to remove an Event based on its ID from your API, which code snippet defines that request in Retrofit? - [ ] @DELETE("events) fun deleteEvent(@Path("id") id: Long): Call - [x] @DELETE("events/{id}") fun deleteEvent(@Path("id") id: Long): Call - [ ] @REMOVE("events/{id}") fun deleteEvent(@Path("id") id: Long): Call - [x] @DELETE("events/{id}") fun deleteEvent(@Path("id") id: Long): Call #### Q13. When would you use a product flavor in your build setup? - [ ] when you need to have the app's strings present in multiple languages - [ ] when you have to provide different versions of your app based on the physical device size - [ ] when you want to provide different versions of your app based on the device screen density - [x] When you want to provide a different version of your app with custom configuration and resources #### Q14. Given the fragment below, how would you get access to a TextView with an ID of text_home contained in the layout file of a Fragment class? ```java private lateinit var textView: TextView override fun onCreateView(...): View? { val root = inflator.inflator(R>layout.fragment_home, container, false) textView = ?? return root } ``` - [ ] root.getById(R.id.text_home) - [ ] findViewByID(R.id.text_home) - [x] root.findViewById(R.id.text_home) - [ ] root.find(R.id.text_home) #### Q15. Why do you use the AndroidJUnitRunner when running UI tests? Notice: AndroidJUnitRunner lets us run JUnit3/4-style tests on Android Devices - [x] The test runner facilitates loading your test package and the app under test onto a device or emulator, runs the test, and reports the results. - [ ] The test runner creates screenshots of each screen that is displayed while tests are executed. - [ ] The test runner facilitates the parallelization of test classes by providing for each test class. - [ ] The test runner facilitates interacting with visible elements on a device, regardless of the activity or fragment that has focus. #### Q16. What allows you to properly restore a user's state when an activity is restarted? - [ ] the onSaveInstance()method - [x] all of these answers - [ ] persistent storage - [ ] ViewModel objects [Refrence](https://developer.android.com/topic/libraries/architecture/saving-states) #### Q17. If the main thread is blocked for too long, the system displays the \_ dialog. - [ ] Thread Not Responding - [ ] Application Paused - [x] Application Not Responding - [ ] Application Blocked #### Q18. How would you retrieve the value of a user's email from SharedPreferences while ensuring that the returned value is not null? - [ ] getPreferances(this).getString(Email,"") - [ ] getDefaultSharedPrefarances(this).getString(EMAIL,null) - [x] getDefaultSharedPreferances(this).getString(EMAIL,"") - [ ] getPreferances(this).getString(EMAIL,null) **Explanation:** `In Method "getDefaultSharedPrefarances(this).getString()" The Second parameter is passed so that it can be returned, in case the key doesn't exist. So we need to pass an empty string to be returned in case the key doesn't exist.` #### Q19. Why is it problematic to define sizes using pixels on Android? - [ ] Although screen pixel density varies, this does not impact the use of pixels to define sizes. - [ ] Large devices always have more pixels, so your UI elements will be affected if you define them with pixels. - [x] The same number of pixels may correspond to different physical sizes, affecting the appearance of your UI elements. - [ ] Different devices have different understandings of what a pixel is, affecting the appearance of your UI elements [Reference](https://developer.android.com/training/multiscreen/screendensities#:~:text=The%20first%20pitfall%20you%20must,physical%20sizes%20on%20different%20devices.) #### Q20. You need to get a list of devices that are attached to your computer with USB debugging enabled. Which command would execute using the Android Debug Bridge? - [ ] list devices - [x] adb devices - [ ] list avd - [ ] dir devices #### Q21. Which drawable definition allows you to achieve the shape below? ![img](image/shape.png?raw=png) - [ ] A ```xml ``` - [ ] B ```xml ``` - [x] C ```xml ``` - [ ] D ```xml ``` #### Q22. To persist a small collection of key-value data, what should you use? - [ ] external file storage - [x] SharedPereferences - [ ] SQLite - [ ] internal file storage #### Q23. You need to retrieve a list of photos from an API. Which code snippet defines an HTML GET request in Retrofit? - [ ] @GET("photo/{id}"} fun listPhotos(@Path("id") id:Long?) : Call - [ ] @LIST("photo") fun listPhotos() : Call> - [ ] @GET("photo") fun listPhotos() : Call - [x] @GET("photo") fun listPhotos() : Call> #### Q24. Given the test class below, which code snippet would be a correct assertion? - [ ] assertThat(resultAdd).is(2.0) - [x] assertNotNull(resultAdd) - [ ] assertThat(resultAdd).isWqualTo(2.0) - [ ] assertThat(resultAdd) #### Q25. What tag should you use to add a reusable view component to a layout file? - [ ] `` - [x] `` - [ ] `` - [ ] `` #### Q26. You want to provide a different drawable for devices that are in landscape mode and whose language is set to French. which directory is named correctly? - [ ] fr-land-drawable - [x] drawable-fr-land - [ ] drawable-french-land - [ ] french-land-drawable #### Q27. Why might you need to include the following permission to your app? `android.permission.ACCESS_NETWORK_STATE` - [ ] to monitor the location of the devices so that you don't attempt to make network calls when the user is stationary - [ ] to request the ability to make network calls from your app - [ ] to monitor the network state of the device so that you can display an in-app banner to the user - [x] to monitor the network state of the devices so that you don't attempt to make network calls when the network is unavailable #### Q28. Which image best corresponds to the following `LinearLayout`? ```xml