








































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Focuses on building real applications using Android SDK. Includes UI/UX design with XML layouts, RecyclerView patterns, REST API consumption, Room database usage, background tasks with WorkManager, permissions model, material design principles, and application architecture patterns like MVVM.
Typology: Exams
1 / 80
This page cannot be seen from the preview
Don't miss anything!









































































Question 1. Which file in an Android project contains declarations of activities, services, permissions, and intent filters? A) build.gradle B) AndroidManifest.xml C) res/values/strings.xml D) src/main/java/MainActivity.kt Answer: B Explanation: The AndroidManifest.xml is the central configuration file where you declare all components, required permissions, and intent filters for the app. Question 2. In a Gradle build script, which block is used to define different build variants such as “debug” and “release”? A) repositories B) dependencies C) android { buildTypes { … } } D) plugins Answer: C Explanation: The buildTypes block inside the android section defines build variants like debug and release, allowing different configurations for each. Question 3. Which Kotlin language feature helps prevent NullPointerException by forcing the developer to handle nullable types explicitly? A) Extension functions B) Coroutines C) Null safety (? and !!) D) Data classes Answer: C Explanation: Kotlin’s null safety forces you to declare a type as nullable (?) and requires explicit handling, reducing runtime NPEs.
Question 4. What is the correct order of callbacks when an activity is first launched and becomes visible to the user? A) onCreate → onStart → onResume B) onStart → onCreate → onResume C) onResume → onStart → onCreate D) onCreate → onResume → onStart Answer: A Explanation: When an activity starts, onCreate() is called first, then onStart(), and finally onResume() when it gains focus. 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) onStop() C) onSaveInstanceState() D) onDestroy() Answer: C Explanation: onSaveInstanceState() receives a Bundle where you can store UI state that Android will restore in onCreate() or onRestoreInstanceState(). Question 6. When the device rotates, which configuration change can be handled automatically by Android without recreating the activity if you declare it in the manifest? A) screen orientation B) locale C) UI mode (night/day) D) smallest width Answer: A Explanation: Adding android:configChanges="orientation|screenSize" in the manifest tells Android you will handle orientation changes yourself, preventing activity recreation.
Question 10. Which permission level requires the user to grant it at runtime on Android 6.0 (API 23) and higher? A) Normal permission B) Signature permission C) Dangerous permission D) System permission Answer: C Explanation: Dangerous permissions (e.g., CAMERA, LOCATION) must be requested at runtime, whereas normal permissions are granted at install time. Question 11. In a ConstraintLayout, which constraint connects a view’s start edge to the parent’s start edge? A) app:layout_constraintLeft_toLeftOf B) app:layout_constraintStart_toStartOf C) app:layout_constraintTop_toTopOf D) app:layout_constraintEnd_toEndOf Answer: B Explanation: layout_constraintStart_toStartOf="parent" aligns the view’s start edge with the parent’s start edge, supporting RTL layouts. Question 12. Which resource qualifier would you use to provide a layout optimized for tablets with a minimum width of 600dp? A) layout-sw600dp B) layout-land C) layout-xlarge D) layout-w600dp Answer: A Explanation: The -sw600dp qualifier targets devices whose smallest width is at least 600dp, commonly used for tablets. Question 13. Which class is responsible for binding data to a RecyclerView’s items?
A) LayoutManager B) Adapter C) ViewHolder D) ItemDecoration Answer: B Explanation: The RecyclerView.Adapter creates ViewHolders and binds data to each item view. Question 14. In Jetpack Compose, which function is used to remember a mutable state that survives recomposition? A) rememberMutableStateOf() B) mutableStateOf() C) remember { mutableStateOf() } D) state { mutableStateOf() } Answer: C Explanation: remember { mutableStateOf(initial) } stores a state object that survives recompositions but is cleared when the composable leaves the composition. Question 15. Which modifier chain adds padding of 16dp and a background color to a composable? A) Modifier.background(Color.Gray).padding(16.dp) B) Modifier.padding(16.dp).background(Color.Gray) C) Modifier.size(16.dp).background(Color.Gray) D) Modifier.fillMaxSize().padding(16.dp) Answer: B Explanation: Modifiers are applied in order; padding first, then background, so the background respects the padded area. Question 16. What is the purpose of the @Composable annotation in Jetpack Compose? A) Marks a class as a ViewModel
B) object C) data class D) sealed class Answer: C Explanation: data class generates boilerplate methods for value-based objects. Question 20. Which Android component can receive system-wide broadcast events such as BOOT_COMPLETED? A) Service B) Activity C) BroadcastReceiver D) ContentProvider Answer: C Explanation: BroadcastReceiver subclasses listen for broadcast Intents, including system events like BOOT_COMPLETED. Question 21. What does the android:exported attribute control in a component declaration? A) Whether the component can be instantiated by the system. B) Whether the component is visible to other applications. C) Whether the component runs in a separate process. D) Whether the component uses a theme. Answer: B Explanation: android:exported="true" makes the component accessible to other apps; false restricts it to the same app. Question 22. Which coroutine builder is recommended for launching UI-related work in an Android Activity? A) launch(Dispatchers.IO) B) async(Dispatchers.Default) C) lifecycleScope.launch { … }
D) GlobalScope.launch { … } Answer: C Explanation: lifecycleScope is tied to the Activity’s lifecycle, preventing leaks, and runs on the Main dispatcher by default. Question 23. Which XML attribute defines a string resource reference for a button’s text? A) android:id="@string/submit" B) android:text="@string/submit" C) android:label="@string/submit" D) android:name="@string/submit" Answer: B Explanation: android:text expects a string, and @string/submit references the string resource. Question 24. When using ViewBinding, which generated class corresponds to a layout file named activity_main.xml? A) ActivityMainBinding B) MainActivityBinding C) ActivityMainViewBinding D) ActivityMainLayoutBinding Answer: A Explanation: ViewBinding generates a class named Binding, so activity_main.xml becomes ActivityMainBinding. Question 25. Which method of a Service is called when a client binds to it using bindService()? A) onStartCommand() B) onCreate() C) onBind() D) onRebind() Answer: C
Question 29. What is the default launch mode of an Activity if none is specified in the manifest? A) singleTop B) singleTask C) standard D) singleInstance Answer: C Explanation: The default mode standard creates a new instance of the Activity each time it is launched. Question 30. Which Compose function provides a Material Design top app bar? A) TopAppBar() B) AppBarTop() C) ScaffoldTopBar() D) MaterialTopBar() Answer: A Explanation: TopAppBar is the composable that implements the Material top app bar. Question 31. In a RecyclerView, which method is called when the RecyclerView needs to create a new ViewHolder? A) onBindViewHolder() B) getItemCount() C) onCreateViewHolder() D) getItemViewType() Answer: C Explanation: onCreateViewHolder() inflates the item layout and returns a new ViewHolder. Question 32. Which Android Studio feature automatically generates a ViewModel class with a factory for a fragment?
A) New > Kotlin Class B) Scaffold > ViewModel C) File > New > Activity > Empty Activity (with ViewModel) D) New > Android > Activity > Fragment (with ViewModel) Answer: D Explanation: The “Fragment (with ViewModel)” wizard creates a ViewModel class and a factory for the fragment. Question 33. Which method should you override in a BroadcastReceiver to perform work when the broadcast is received? A) onReceive() B) onStartCommand() C) onBroadcast() D) onHandleIntent() Answer: A Explanation: onReceive(Context, Intent) is invoked when the receiver catches a matching broadcast. Question 34. Which of the following is NOT a valid way to start an Activity for a result in modern Android? A) startActivityForResult() B) registerForActivityResult() with ActivityResultContracts.StartActivityForResult C) ActivityResultLauncher.launch() D) Using the Navigation component’s navigate() with a result bundle Answer: A Explanation: startActivityForResult() is deprecated; the recommended approach uses registerForActivityResult(). Question 35. What does the android:hardwareAccelerated="true" attribute affect? A) Enables GPU rendering for the activity’s window. B) Allows the app to access device sensors.
Answer: A Explanation: android:excludeFromRecents="true" removes the activity from the recent tasks list. Question 39. What is the primary advantage of using ConstraintLayout over nested LinearLayouts? A) It supports data binding automatically. B) It reduces view hierarchy depth, improving layout performance. C) It automatically adds animations. D) It requires no XML. Answer: B Explanation: ConstraintLayout enables flat, complex layouts without deep nesting, which improves rendering performance. Question 40. Which annotation is used to indicate that a Kotlin function should be called on the main thread? A) @MainThread B) @UiThread C) @WorkerThread D) @BackgroundThread Answer: B Explanation: @UiThread (or @MainThread) signals that the method must run on the UI thread; Android’s lint checks enforce this. Question 41. In the Navigation Component, what XML element defines a destination that is a fragment? A) B) C) D) Answer: B
Explanation: Inside a navigation graph, `` tags declare fragment destinations. Question 42. Which method of a ViewModel should you override to clean up resources when the ViewModel is no longer needed? A) onCleared() B) onDestroy() C) onStop() D) onDetach() Answer: A Explanation: onCleared() is called when the ViewModel is about to be destroyed, allowing you to release resources. Question 43. Which of the following statements about WorkManager is true? A) It can only schedule work when the device is charging. B) It uses a SQLite database to persist work across device reboots. C) It runs tasks only on the main thread. D) It replaces AlarmManager for exact timing. Answer: B Explanation: WorkManager persists work in a database, ensuring tasks survive process death and device reboots. Question 44. In a Compose @Composable function, which of the following is the correct way to observe a LiveData from a ViewModel? A) val text = viewModel.liveDataString.observeAsState().value B) val text = viewModel.liveDataString.value C) val text = viewModel.liveDataString.get() D) val text = viewModel.liveDataString.collectAsState() Answer: A Explanation: observeAsState() converts LiveData into a Compose State, and .value retrieves the current value.
Question 48. Which Android system service provides access to the device’s location providers? A) SensorManager B) LocationManager C) ConnectivityManager D) PowerManager Answer: B Explanation: LocationManager allows querying GPS, network, and passive location providers. Question 49. In Kotlin, which scope function is best suited for executing a block of code only when an object is non-null? A) let B) run C) also D) apply Answer: A Explanation: let is invoked only when the receiver is non-null, making it ideal for null-safe operations. Question 50. Which attribute in a layout XML file defines a view’s width to match the parent’s width? A) android:layout_width="wrap_content" B) android:layout_width="match_parent" C) android:layout_width="fill_parent" (deprecated) D) Both B and C are acceptable. Answer: D Explanation: match_parent is the modern name; fill_parent works but is deprecated. Question 51. What is the purpose of the android:exported attribute introduced in Android 12 for components with intent filters?
A) To enforce that components with intent filters must explicitly declare their export status. B) To enable component sharing across processes automatically. C) To allow the system to decide based on permissions. D) To specify the component’s theme. Answer: A Explanation: Starting with Android 12, components that have intent filters must set android:exported to true or false, making intent exposure explicit. Question 52. Which of the following is a correct way to start a foreground service on Android O (API 26) and higher? A) startService(intent) B) startForegroundService(intent) C) bindService(intent, connection, BIND_AUTO_CREATE) D) ContextCompat.startForegroundService(context, intent) Answer: D Explanation: ContextCompat.startForegroundService() handles the API differences and starts a foreground service safely. Question 53. In a Compose LazyColumn, which parameter controls the composable that defines each item’s UI? A) itemContent B) items C) item { … } D) content Answer: C Explanation: Inside a LazyColumn, you use item { … } or items(list) { … } to define each row’s UI. Question 54. Which method of Fragment is called after the fragment’s view hierarchy has been created? A) onCreate()
D) The app from being launched from the home screen. Answer: B Explanation: Setting allowBackup="false" disables Android’s automatic backup of the app’s data. Question 58. Which annotation is used to generate a ViewBinding class for a layout named item_user.xml? A) @BindingAdapter B) @LayoutRes C) @ViewBinding D) No annotation; ViewBinding is enabled via Gradle. Answer: D Explanation: ViewBinding is enabled in build.gradle with viewBinding { enabled = true }; no annotation is required. Question 59. In a FragmentTransaction, which method adds the transaction to the back stack? A) addToBackStack(null) B) commit() C) replace() D) setReorderingAllowed(true) Answer: A Explanation: addToBackStack() records the transaction so the user can navigate back. Question 60. Which of the following is the correct way to request a dangerous permission (e.g., CAMERA) at runtime in an Activity? A) requestPermissions(arrayOf(Manifest.permission.CAMERA), REQUEST_CODE) B) ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), REQUEST_CODE) C) ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) D) Both A and B are valid.
Answer: D Explanation: Both requestPermissions (API 23) and the support library’s ActivityCompat.requestPermissions achieve the same result. Question 61. Which Android component is primarily used to expose a structured set of data to other apps via a URI? A) Service B) ContentProvider C) BroadcastReceiver D) Activity Answer: B Explanation: ContentProvider manages data access through a content URI, enabling inter-app data sharing. Question 62. In Compose, which function creates a Material Design button with a click listener? A) Button(onClick = { … }) { Text("OK") } B) MaterialButton(onClick = { … }) { Text("OK") } C) ClickableButton(onClick = { … }) { Text("OK") } D) ComposeButton(onClick = { … }) { Text("OK") } Answer: A Explanation: The Button composable from Material implements a clickable button. Question 63. Which layout parameter should you use to make a view occupy the remaining space in a LinearLayout? A) android:layout_weight="1" B) android:layout_gravity="fill" C) android:layout_span="1" D) android:layout_fillParent="true" Answer: A