Docsity

Android Application Development Practice Exam, Exams of Technology

Toggle sidebar
bg1
Android Application Development Practice
Exam
**Question 1.** Which file in an Android project declares activities, services, permissions, and
intent filters?
A) build.gradle
B) AndroidManifest.xml
C) MainActivity.kt
D) res/values/strings.xml
Answer: B
Explanation: The AndroidManifest.xml is the central place where components such as activities,
services, broadcast receivers, content providers, required permissions, and intent filters are
declared.
**Question 2.** In a Gradle build script, which block is used to define different build variants
such as “debug” and “release”?
A) dependencies {}
B) android {}
C) buildTypes {}
D) flavorDimensions {}
Answer: C
Explanation: The buildTypes block inside the android DSL specifies build variants like debug and
release, allowing configuration of signing configs, minification, and other properties.
**Question 3.** Which Kotlin language feature helps avoid NullPointerException by forcing the
compiler to check for null at compile time?
A) lateinit
B) safe cast (as?)
C) null safety with “?” and “!!” operators
D) extension functions
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e

Partial preview of the text

Download Android Application Development Practice Exam and more Exams Technology in PDF only on Docsity!

Exam

Question 1. Which file in an Android project declares activities, services, permissions, and intent filters? A) build.gradle B) AndroidManifest.xml C) MainActivity.kt D) res/values/strings.xml Answer: B Explanation: The AndroidManifest.xml is the central place where components such as activities, services, broadcast receivers, content providers, required permissions, and intent filters are declared. Question 2. In a Gradle build script, which block is used to define different build variants such as “debug” and “release”? A) dependencies {} B) android {} C) buildTypes {} D) flavorDimensions {} Answer: C Explanation: The buildTypes block inside the android DSL specifies build variants like debug and release, allowing configuration of signing configs, minification, and other properties. Question 3. Which Kotlin language feature helps avoid NullPointerException by forcing the compiler to check for null at compile time? A) lateinit B) safe cast (as?) C) null safety with “?” and “!!” operators D) extension functions

Exam

Answer: C Explanation: Kotlin’s null safety introduces nullable types (e.g., String?) and the safe-call operator “?” as well as the non-null assertion “!!”, enabling compile‑time null checks. Question 4. What is the correct order of callbacks when an activity is launched for the first time and becomes visible to the user? A) onCreate → onStart → onResume → onPause → onStop → onDestroy B) onStart → onCreate → onResume → onPause → onStop → onDestroy C) onCreate → onStart → onResume D) onResume → onStart → onCreate Answer: C Explanation: When an activity starts, the system calls onCreate(), then onStart(), and finally onResume() before the UI is presented to the user. Question 5. Which method should you override to save transient UI state before an activity may be destroyed due to a configuration change? A) onPause() B) onSaveInstanceState() C) onDestroy() D) onStop() Answer: B Explanation: onSaveInstanceState(Bundle outState) is invoked before the activity may be destroyed, allowing you to store UI state into the Bundle. Question 6. How can you prevent an activity from being destroyed on a device rotation? A) Declare android:configChanges="orientation|screenSize" in the manifest B) Call setRetainInstance(true) in the activity

Exam

Question 9. Which broadcast type guarantees that receivers will receive the broadcast in a defined order? A) Normal broadcast B) Sticky broadcast C) Ordered broadcast D) Local broadcast Answer: C Explanation: Ordered broadcasts are delivered to one receiver at a time based on priority, allowing each to consume or modify the Intent. Question 10. When requesting a dangerous permission at runtime, which callback receives the user's response? A) onRequestPermissionsResult() B) onPermissionsResult() C) onActivityResult() D) onPermissionGranted() Answer: A Explanation: The Activity (or Fragment) receives the result in onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults). Question 11. Which Intent action opens the device’s dialer with a phone number pre‑filled but does not place the call automatically? A) ACTION_CALL B) ACTION_DIAL C) ACTION_VIEW D) ACTION_SENDTO Answer: B

Exam

Explanation: ACTION_DIAL launches the dialer UI with the supplied tel: URI, letting the user press the call button manually. Question 12. In a layout XML file, which attribute of ConstraintLayout connects a view’s start edge to another view’s end edge? A) layout_constraintStart_toStartOf B) layout_constraintEnd_toEndOf C) layout_constraintStart_toEndOf D) layout_constraintBottom_toTopOf Answer: C Explanation: layout_constraintStart_toEndOf creates a start‑to‑end constraint, aligning the start edge of the view with the end edge of the referenced view. Question 13. Which resource qualifier would you use to provide a different layout for tablets with a minimum width of 600dp? A) layout-sw600dp B) layout-land C) layout-xlarge D) layout-w600dp Answer: A Explanation: The “sw” qualifier stands for smallest width; layout-sw600dp is selected on devices whose smallest dimension is at least 600dp, typical for tablets. Question 14. What is the purpose of the ViewHolder pattern in a RecyclerView.Adapter? A) To hold a reference to the entire RecyclerView B) To cache view lookups and improve scrolling performance C) To store the data set for the adapter

Exam

B) Modifier.center() C) Modifier.gravity(Gravity.Center) D) Modifier.layoutId("center") Answer: A Explanation: Modifier.align(Alignment.Center) positions the composable in the center of the Box or other parent that supports alignment. Question 18. How does state hoisting improve composable reusability? A) By storing state in a global variable B) By moving state ownership to the caller and passing it as parameters C) By using static fields inside composables D) By converting mutable state to immutable data classes only Answer: B Explanation: State hoisting means the composable does not own mutable state; instead, the parent supplies the state and a callback to update it, making the composable stateless and reusable. Question 19. Which Jetpack library provides a type‑safe way to navigate between fragments using generated directions? A) Navigation Component B) Safe Args plugin C) FragmentManager D) ActivityResultContracts Answer: B Explanation: The Safe Args Gradle plugin generates Directions classes for the Navigation Component, enabling compile‑time safe argument passing.

Exam

Question 20. What is the default launch mode for an activity if none is specified in the manifest? A) singleTop B) singleTask C) standard D) singleInstance Answer: C Explanation: The standard launch mode creates a new instance of the activity each time it is launched. Question 21. Which annotation is used to indicate that a Kotlin function should be executed on the main (UI) thread when using coroutines? A) @MainThread B) @UiThread C) @Dispatcher(IO) D) withContext(Dispatchers.Main) inside the function body Answer: D Explanation: Coroutines themselves are not annotated for thread confinement; you switch to the main thread with withContext(Dispatchers.Main) inside the suspend function. Question 22. In Android Room, which annotation marks a method that returns a list of all rows from a table? A) @Insert B) @Query("SELECT * FROM table_name") C) @Update D) @Delete Answer: B

Exam

D) runtimeOnly Answer: C Explanation: compileOnly adds the dependency to the compile classpath but excludes it from the packaged APK. Question 26. Which AndroidX library provides lifecycle‑aware components such as LiveData and ViewModel? A) androidx.core B) androidx.lifecycle C) androidx.navigation D) androidx.room Answer: B Explanation: The androidx.lifecycle package contains LifecycleOwner, LiveData, ViewModel, and related classes. Question 27. In a Fragment, which method is called to create the view hierarchy associated with the fragment? A) onCreate() B) onCreateView() C) onViewCreated() D) onStart() Answer: B Explanation: onCreateView() inflates and returns the fragment’s root view. Question 28. Which XML attribute enables data binding for a layout file? A) android:bindingEnabled="true"

Exam

B) root tag C) dataBinding="enabled" D) tools:dataBinding="true" Answer: B Explanation: Wrapping the layout with a tag activates the Data Binding compiler, allowing elements and binding expressions. Question 29. What is the purpose of the “android:exported” attribute introduced in Android 12 (API 31)? A) To define whether a component can be launched by other apps B) To indicate if a resource is public C) To control whether a service runs in the foreground D) To specify if an activity should be retained after rotation Answer: A Explanation: android:exported="true" or "false" tells the system whether the component (activity, service, receiver, provider) is accessible to other apps. Question 30. Which testing framework is used for writing UI tests that interact with the app’s UI components on a device or emulator? A) JUnit B) Espresso C) Robolectric D) Mockito Answer: B Explanation: Espresso provides APIs to simulate user actions and verify UI state on real devices or emulators.

Exam

Question 34. Which Android component is best suited for playing short audio clips that need to respect the device’s volume controls? A) MediaPlayer B) SoundPool C) ExoPlayer D) AudioTrack Answer: B Explanation: SoundPool is optimized for low‑latency playback of short sound effects and automatically follows the device’s stream volume. Question 35. What is the purpose of the “android:windowSoftInputMode” attribute in the manifest? A) To control how the soft keyboard interacts with the activity’s layout B) To enable hardware acceleration for the window C) To set the theme of the activity D) To define the orientation of the activity Answer: A Explanation: android:windowSoftInputMode can be set to “adjustResize”, “adjustPan”, etc., dictating how the UI behaves when the soft keyboard appears. Question 36. Which of the following is a correct way to start an Activity for a result using the modern Activity Result API? A) startActivityForResult(intent, REQUEST_CODE) B) registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result - > … } C) onActivityResult(requestCode, resultCode, data) D) launchActivity(intent)

Exam

Answer: B Explanation: The new Activity Result API replaces startActivityForResult with registerForActivityResult and a contract. Question 37. In a Compose UI, which function is used to provide a MaterialTheme to its children? A) MaterialTheme() B) ThemeProvider() C) AppTheme() D) ComposeTheme() Answer: A Explanation: MaterialTheme composable supplies colors, typography, and shapes to its descendant composables. Question 38. Which AndroidX library provides a convenient bullpen for handling paging of large data sets in RecyclerView? A) androidx.paging B) androidx.recyclerview C) androidx.lifecycle D) androidx.room Answer: A Explanation: The Paging library (androidx.paging) loads data incrementally and integrates with RecyclerView adapters. Question 39. What does the “android:exported” attribute default to for activities that have intent filters on Android 12 and higher? A) true

Exam

Question 42. Which manifest element is required to declare a ContentProvider? A) B) C) D) Answer: C Explanation: The tag registers a ContentProvider component. Question 43. What is the primary purpose of the “android:allowBackup” attribute in the manifest? A) To enable cloud backup of the app’s data via Android Backup Service B) To allow the app to be installed on external storage C) To permit the app to receive broadcast messages D) To enable multi‑window mode Answer: A Explanation: android:allowBackup="true" allows the system to back up the app’s data to the cloud and restore it on a new device. Question 44. Which Gradle plugin is required to enable Jetpack Compose in an Android module? A) kotlin-android B) android-application C) kotlin-kapt D) compose-android Answer: A (plus specific compose options)

Exam

Explanation: The kotlin-android plugin is needed, and you also enable composeOptions { kotlinCompilerExtensionVersion = "…" } within the android block. Question 45. Which of the following is the correct way to retrieve a string extra from an Intent in Kotlin? A) intent.getStringExtra("key")!! B) intent.getString("key") C) intent.extras["key"] as String D) intent.getExtraString("key") Answer: A Explanation: getStringExtra returns a nullable String; using !! forces a non‑null value (or throws if missing). Question 46. In Android, which component is responsible for handling asynchronous tasks on a background thread without blocking the UI? A) AsyncTask (deprecated) B) ThreadPoolExecutor only C) HandlerThread D) WorkManager (for deferrable work) Answer: D (most appropriate modern answer) Explanation: WorkManager schedules background work that respects constraints and runs off the UI thread, superseding AsyncTask. Question 47. Which of the following is NOT a valid way to pass data between fragments? A) Using a shared ViewModel scoped to the activity B) Using fragment arguments Bundle C) Directly accessing another fragment’s views

Exam

B) Google Play generates device‑specific APKs from the bundle, reducing download size. C) They cannot contain native libraries. D) They replace the need for ProGuard/R8. Answer: B Explanation: App Bundles allow Google Play to deliver split APKs tailored to the device’s configuration, decreasing download size. Question 51. Which method of the NotificationCompat.Builder must be called to set the notification’s priority on Android 7.1 (API 25) and lower? A) setImportance() B) setPriority() C) setCategory() D) setVisibility() Answer: B Explanation: setPriority() defines the urgency of a notification on pre‑Oreo devices; from Oreo onward, importance is set via NotificationChannel. Question 52. Which XML attribute specifies that a view should fill the remaining space in a LinearLayout? A) layout_weight="1" B) layout_gravity="fill" C) layout_width="match_parent" D) layout_height="wrap_content" Answer: A Explanation: layout_weight distributes remaining space among children; a weight of 1 tells the view to take all extra space.

Exam

Question 53. Which Android system service provides location updates based on GPS, Wi‑Fi, and cell towers? A) SensorManager B) LocationManager C) ConnectivityManager D) PowerManager Answer: B Explanation: LocationManager (or the newer FusedLocationProviderClient) supplies location data from various providers. Question 54. What does the “android:hardwareAccelerated” attribute control? A) Whether the app can use the device’s GPU for rendering UI B) Whether the app can access the camera hardware C) Whether the app can run in split‑screen mode D) Whether the app can use BLE hardware Answer: A Explanation: hardwareAccelerated enables GPU‑based rendering, improving UI performance. Question 55. Which of the following is the correct way to define a sealed class in Kotlin that can be used for representing UI states? A) sealed class UiState { object Loading; data class Success(val data: List) } B) sealed interface UiState { class Loading() ; class Success(data: List) } C) abstract class UiState { open fun render() } D) enum class UiState { LOADING, SUCCESS } Answer: A