Android 100 MCQS
Android 100 MCQS
Android UI/UX:
12. Ques How can you pass data between activities in Android?
- A. Using SharedPreferences
- B. Using Intent extras
- C. Using a global variable
- D. Using the SQLite database
13. Ques What is the purpose of an Android Fragment?
- A. Manage background tasks
- B. Handle device orientation changes
- C. Represent a screen or a part of the user interface
- D. Control device hardware
Android Services:
18. Ques How can you communicate between an Activity and a Service in Android?
- A. Using a global variable
- B. Using Intents
- C. Using SharedPreferences
- D. Using the SQLite database
24. Ques How can you register a BroadcastReceiver dynamically in an Android app?
- A. Using the `<receiver>` tag in the AndroidManifest.xml file
- B. Using the `registerReceiver` method in code
- C. Using Intents
- D. Using SharedPreferences
25. Ques What is the difference between an ordered and unordered broadcast in
Android?
- A. Ordered broadcasts are asynchronous, and unordered broadcasts are
synchronous
- B. Ordered broadcasts guarantee the order of delivery, unordered broadcasts do not
- C. Ordered broadcasts are more efficient
- D. There is no difference
30. Ques What is the difference between internal and external storage in Android?
- A. Internal storage is faster
- B. External storage is non-removable, while internal storage is removable
- C. Internal storage is always private to the app, external storage is shared
- D. There is no difference
Android Networking:
Android Security:
40. Ques How can you prevent security vulnerabilities like SQL injection in Android?
- A. Use the `WebView` component
- B. Sanitize user inputs and use parameterized queries
- C. Use the `AsyncTask` class
- D. Use the `BroadcastReceiver` class
Android Multithreading:
Android Lifecycle:
52. Ques What is the purpose of the `onCreate` method in an Android Activity?
- A. Initialize the activity and load UI elements
- B. Handle device orientation changes
- C. Perform background tasks
- D. Define app permissions
53. Ques When is the `onStart` method called in the Android Activity lifecycle?
- A. After `onCreate`
- B. After `onPause`
- C. After `onStop`
- D.
After `onResume`
54. Ques What is the purpose of the `onPause` method in an Android Activity?
- A. Perform background tasks
- B. Save the current state of the activity
- C. Initialize the activity
- D. Define app permissions
55. Ques When is the `onDestroy` method called in the Android Activity lifecycle?
- A. Before `onCreate`
- B. Before `onPause`
- C. Before `onStop`
- D. Before `onResume`
Android Fragments:
57. Ques What is the purpose of the `onCreateView` method in an Android Fragment?
- A. Perform background tasks
- B. Initialize the fragment and load UI elements
- C. Save the current state of the fragment
- D. Define app permissions
58. Ques When is the `onAttach` method called in the Android Fragment lifecycle?
- A. Before `onCreate`
- B. Before `onCreateView`
- C. Before `onResume`
- D. Before `onDetach`
59. Ques What is the purpose of the `onPause` method in an Android Fragment?
- A. Perform background tasks
- B. Save the current state of the fragment
- C. Initialize the fragment
- D. Define app permissions
60. Ques How can you communicate between two Fragments in an Activity?
- A. Using shared preferences
- B. Using a global variable
- C. Using Intents
- D. Using interface callbacks
Android RecyclerView:
62. Ques What is the difference between `RecyclerView` and `ListView` in Android?
- A. `RecyclerView` is for displaying grids, `ListView` for lists
- B. `RecyclerView` is more flexible and efficient than `ListView`
- C. `RecyclerView` is older than `ListView`
- D. There is no difference
65. Ques What is the purpose of the `ViewHolder` pattern in Android's `RecyclerView`?
- A. Manage UI layout
- B. Improve the performance of the `RecyclerView` by reusing views
- C. Handle background tasks
- D. Define app permissions
67. Ques What is the role of the `ViewModel` in Android Architecture Components?
- A. Manage UI layout
- B. Store and manage UI-related data, ensuring data survives configuration changes
- C. Handle network operations
- D. Define app permissions
68. Ques What is the purpose of LiveData in Android Architecture Components?
- A. Manage background tasks
- B. Observe and react to changes in the app's data
- C. Handle user interactions
- D. Define app navigation
70. Ques How does the Repository pattern work in Android Architecture Components?
- A. Manage UI layout
- B. Abstract the data source from the rest of the app, providing a clean API for data
access
- C. Handle background tasks
- D. Define app permissions
71. Ques How does the `ViewModel` survive configuration changes in Android?
- A. It is reinitialized
- B. It is saved in the savedInstanceState
- C. It is recreated using a `ViewModelProvider`
- D. It is destroyed and recreated from scratch
72. Ques What is the purpose of the `onCleared` method in the Android `ViewModel`?
- A. Manage UI layout
- B. Called when the `ViewModel` is no longer used and will be destroyed
- C. Handle background tasks
- D. Define app permissions
73. Ques What is the difference between `LiveData` and `Observable` in Android?
- A. There is no difference
- B. `LiveData` is part of the Android Architecture Components, while `Observable` is
not
- C. `Observable` is used for UI updates, `LiveData` is not
- D. `Observable` is used for background tasks, `LiveData` is used for UI updates
75. Ques What is the purpose of the `Transformations` class in Android's `LiveData`?
- A. Manage UI layout
- B. Perform transformations on `LiveData` objects
- C. Handle background tasks
- D. Define app permissions
Android Room Database:
76. Ques What is the purpose of the Room Persistence Library in Android?
- A. Manage UI layout
- B. Provide an abstraction layer over SQLite to allow for more robust database access
- C. Handle background tasks
- D. Define app permissions
78. Ques What is the role of the `@PrimaryKey` annotation in a Room database entity?
- A. Manage UI layout
- B. Define a primary key for the entity
- C. Handle background tasks
- D. Define app permissions
79. Ques How can you perform CRUD (Create, Read, Update, Delete) operations in a
Room database?
- A. Using the `IntentService` class
- B. Using the `BroadcastReceiver` class
- C. Using the `RoomDatabase` class
- D. Using the `RoomDAO` interface
80. Ques What is the purpose of the `@Query` annotation in a Room database DAO
(Data Access Object)?
- A. Manage UI layout
- B. Define a database query
- C. Handle background tasks
- D. Define app permissions
Android Navigation:
85. Ques How can you pass data between destinations in Android Navigation?
- A. Using shared preferences
- B. Using the `IntentService` class
- C. Using the `NavController` and Safe Args
- D. Using the `BroadcastReceiver` class
Android Testing:
86. Ques What is the purpose of Android testing libraries like Espresso and JUnit?
- A. Manage UI layout
- B. Provide a framework for testing Android applications
- C. Handle background tasks
- D. Define app permissions
87. Ques What is Espresso in the context of Android testing?
- A. A UI element
- B. A background process
- C. A testing framework for UI testing
- D. A type of layout in Android
88. Ques How can you write a UI test using Espresso in Android?
- A. By creating a new activity
- B. By writing test cases using the `ActivityTestRule` and `Espresso` classes
- C. By using the `IntentService` class
- D. By using the `BroadcastReceiver` class
89. Ques What is the purpose of the `@RunWith` annotation in JUnit in Android
testing?
- A. Manage UI layout
- B. Specify the test runner class
- C. Handle background tasks
- D. Define app permissions
90. Ques How can you perform unit testing in Android using JUnit?
- A. By creating a new activity
- B. By writing test cases for individual units of code using JUnit
- C. By using the `IntentService` class
- D. By using the `BroadcastReceiver` class
Android Broadcasts:
94. Ques How can you register a BroadcastReceiver dynamically in an Android app?
- A. Using the `<receiver>` tag in the AndroidManifest.xml file
- B. Using the `registerReceiver` method in code
- C. Using Intents
- D. Using SharedPreferences
95. Ques What is the difference between a local and global broadcast in Android?
- A. Local broadcasts are sent within the app, global broadcasts are system-wide
- B. Global broadcasts are sent within the app, local broadcasts are system-wide
- C. There is no difference
- D. Local broadcasts are synchronous, global broadcasts are asynchronous
98. Ques What is Firebase Cloud Messaging (FCM) used for in Android?
- A. Manage UI layout
- B. Send and receive push notifications
- C. Handle background tasks
- D. Define app permissions
99. Ques What is the Android WorkManager used for?
- A. Manage UI layout
- B. Perform background tasks in a way that is both guaranteed to execute and
deferrable
- C. Handle device orientation changes
- D. Define app permissions
103. Ques How can you use Dagger 2 for Dependency Injection in an Android app?
- A. By creating a new activity
- B. By writing custom code to manage dependencies
- C. By using the `@Inject` annotation and defining a module
- D. By using the `IntentService` class
108. Ques What is the ViewHolder design pattern used for in Android?
- A. Manage UI layout
- B. Improve the performance of `RecyclerView` by reusing views
- C. Handle background tasks
- D. Define app permissions
115. Ques How does MVVM help in unit testing Android apps?
- A. By providing a clear separation of concerns
- B. By using `IntentService` class
- C. By using the `BroadcastReceiver` class
- D. By using shared preferences
Android Kotlin:
117. Ques How does Kotlin differ from Java in the context of Android development?
- A. Kotlin is a markup language, while Java is a programming language
- B. Kotlin is more concise and expressive than Java
- C. Kotlin is an older language than Java
- D. There is no difference
118. Ques What is the purpose of the Kotlin `null` safety feature?
- A. Manage UI layout
- B. Prevent null pointer exceptions by making types non-nullable by default
- C. Handle background tasks
- D. Define app permissions
123. Ques What is the purpose of the `@Composable` annotation in Jetpack Compose?
- A. Manage UI layout
- B. Specify a composable function that defines a part of the UI
- C. Handle background tasks
- D. Define app permissions
125. Ques What is the purpose of the `remember` function in Jetpack Compose?
- A. Manage UI layout
- B. Save and restore UI-related data across recompositions
- C. Handle background tasks
- D. Define app permissions
Android Kotlin Coroutines:
127. Ques How do Kotlin Coroutines differ from traditional threading approaches?
- A. Kotlin Coroutines are slower than traditional threading
- B. Kotlin Coroutines use cooperative multitasking and can be more efficient than
traditional threading
- C. There is no difference
- D. Kotlin Coroutines are only used for UI tasks
128. Ques What is the purpose of the `suspend` keyword in Kotlin Coroutines?
- A. Manage UI layout
- B. Specify a coroutine that can be suspended and resumed later
- C. Handle background tasks
- D. Define app permissions
Android WorkManager:
132. Ques How does WorkManager differ from other background processing solutions
in Android?
- A. WorkManager is only used for UI tasks
- B. WorkManager is part of the Android Architecture Components and provides a
simple and consistent API
- C. There is no difference
- D. WorkManager is an older technology than other solutions
133. Ques What types of constraints can you apply to a task scheduled with
WorkManager?
- A. Only time constraints
- B. Only network constraints
- C. Time, network, storage, and charging constraints
- D. There are no constraints in WorkManager
134. Ques How can you create a periodic task with WorkManager?
- A. By using the `IntentService` class
- B. By using the `JobIntentService` class
- C. By using the `WorkManager` and `PeriodicWorkRequest` classes
- D. By using the `BroadcastReceiver` class
Android Firebase:
137. Ques How can you integrate Firebase into an Android app?
- A. By creating a new activity
- B. By adding the Firebase SDK to the app and configuring it
- C. By using the `IntentService` class
- D. By using the `BroadcastReceiver` class
139. Ques How can you perform authentication using Firebase in Android?
- A. By using the `IntentService` class
- B. By using the `FirebaseAuth` class and related components
- C. By using the `BroadcastReceiver` class
- D. By using the `Room` database
141. Ques What is the purpose of the Room Persistence Library in Android?
- A. Manage UI layout
- B. Provide an abstraction layer over SQLite to allow for more robust database access
- C. Handle background tasks
- D. Define app permissions
143. Ques What is the role of the `@PrimaryKey` annotation in a Room database
entity?
- A. Manage UI layout
- B. Define a primary key for the entity
- C. Handle background tasks
- D. Define app permissions
144. Ques How can you perform CRUD (Create, Read, Update, Delete) operations in a
Room database
?
- A. Using the `IntentService` class
- B. Using the `BroadcastReceiver` class
- C. Using the `RoomDatabase` class
- D. Using the `RoomDAO` interface
145. Ques What is the purpose of the `@Query` annotation in a Room database DAO
(Data Access Object)?
- A. Manage UI layout
- B. Define a database query
- C. Handle background tasks
- D. Define app permissions
146. Ques What is the purpose of Android testing libraries like Espresso and JUnit?
- A. Manage UI layout
- B. Provide a framework for testing Android applications
- C. Handle background tasks
- D. Define app permissions
148. Ques How can you write a UI test using Espresso in Android?
- A. By creating a new activity
- B. By writing test cases using the `ActivityTestRule` and `Espresso` classes
- C. By using the `IntentService` class
- D. By using the `BroadcastReceiver` class
149. Ques What is the purpose of the `@RunWith` annotation in JUnit in Android
testing?
- A. Manage UI layout
- B. Specify the test runner class
- C. Handle background tasks
- D. Define app permissions
150. Ques How can you perform unit testing in Android using JUnit?
- A. By creating a new activity
- B. By writing test cases for individual units of code using JUnit
- C. By using the `IntentService` class
- D. By using the `BroadcastReceiver` class