Sample Questions and Answers
1. What is the main purpose of the ViewModel
class in Android Architecture Components?
A. To handle background tasks
B. To manage UI-related data in a lifecycle-conscious way
C. To bind XML layouts to Java code
D. To interact with databases
Answer: B
Explanation: The ViewModel
stores and manages UI-related data in a lifecycle-aware manner, surviving configuration changes like screen rotations.
2. Which component is not part of Android Jetpack?
A. Navigation
B. LiveData
C. WorkManager
D. IntentService
Answer: D
Explanation: IntentService
is part of the Android platform, not Android Jetpack. Jetpack includes modern libraries like Navigation and WorkManager.
3. Which method is used to start an Activity
for a result?
A. startActivity(Intent)
B. startActivityForResult(Intent, int)
C. launchActivity(Intent)
D. getResult(Intent)
Answer: B
Explanation: startActivityForResult()
is used to start an Activity when expecting a result back in onActivityResult()
.
4. What annotation ensures that a method runs only on the main thread?
A. @WorkerThread
B. @MainThread
C. @UiThread
D. @ThreadSafe
Answer: B
Explanation: @MainThread
is used to indicate that the method should be called only from the main UI thread.
5. Which LayoutManager would you use for a horizontal scrolling list in RecyclerView?
A. LinearLayoutManager(this)
B. GridLayoutManager(this, 2)
C. LinearLayoutManager(this, HORIZONTAL, false)
D. StaggeredGridLayoutManager(1, VERTICAL)
Answer: C
Explanation: To achieve horizontal scrolling, LinearLayoutManager
must be set with horizontal orientation.
6. What is the recommended way to persist large data sets in Android apps?
A. SharedPreferences
B. SQLite
C. Room
D. Internal Storage
Answer: C
Explanation: Room is the recommended abstraction over SQLite for storing large datasets with compile-time checks and modern APIs.
7. In MVVM, what typically communicates changes from data to UI?
A. ViewModel
B. LiveData
C. Repository
D. Data Binding
Answer: B
Explanation: LiveData
is lifecycle-aware and notifies observers (like UI components) when the data changes.
8. Which API allows navigation between fragments while maintaining back stack?
A. FragmentManager
B. NavHostFragment
C. Intent
D. Navigation Component
Answer: D
Explanation: Navigation Component provides a consistent way to implement navigation, including handling back stack automatically.
9. What does the @Query
annotation do in Room?
A. Marks a primary key
B. Specifies a database schema
C. Defines a SQL query
D. Declares a migration rule
Answer: C
Explanation: @Query
is used to define SQL queries in DAO interfaces.
10. Which method is used to inflate a layout in a RecyclerView Adapter?
A. View.inflate()
B. LayoutInflater.from().inflate()
C. inflateLayout()
D. getLayoutInflater()
Answer: B
Explanation: The correct approach is to use LayoutInflater.from(parent.getContext()).inflate(...)
.
11. What is the function of Manifest.permission.CAMERA
?
A. Grants access to external camera apps
B. Enables camera usage in an app
C. Grants root access
D. Enables app installation
Answer: B
Explanation: It declares that the app needs permission to access the device’s camera.
12. What is the correct way to observe a LiveData
in an Activity?
A. liveData.observe()
B. liveData.observe(this, Observer {})
C. liveData.setObserver()
D. liveData.subscribe()
Answer: B
Explanation: You observe LiveData with observe(this, Observer)
syntax inside an Activity or Fragment.
13. Which file contains metadata like app components and permissions?
A. build.gradle
B. AndroidManifest.xml
C. res/values/strings.xml
D. proguard-rules.pro
Answer: B
Explanation: The manifest file declares components, permissions, and other essential app-level metadata.
14. What does the @Insert
annotation in Room signify?
A. Create table
B. Add a column
C. Insert data into a table
D. Perform update
Answer: C
Explanation: @Insert
tells Room to insert a new entry into the associated database table.
15. What is the purpose of the onSaveInstanceState()
method?
A. Save preferences
B. Save UI state
C. Backup files
D. Save layouts
Answer: B
Explanation: This method saves UI-related data before an Activity is destroyed due to configuration changes.
16. Which library is used for efficient image loading in Android?
A. Volley
B. OkHttp
C. Picasso
D. Retrofit
Answer: C
Explanation: Picasso
is widely used for handling image loading and caching.
17. What does ProGuard do in Android apps?
A. Speed up app startup
B. Secure user data
C. Obfuscate and shrink code
D. Monitor memory
Answer: C
Explanation: ProGuard reduces APK size and makes reverse engineering harder by obfuscating the code.
18. What is the use of WorkManager
in Android Jetpack?
A. Manage Bluetooth devices
B. Schedule precise alarms
C. Execute deferrable, guaranteed background work
D. Handle UI rendering
Answer: C
Explanation: WorkManager
is designed for deferrable and guaranteed background execution.
19. What does the keyword suspend
do in Kotlin?
A. Blocks UI
B. Suspends the app
C. Marks a function to be used in a coroutine
D. Ends the coroutine
Answer: C
Explanation: suspend
marks a function as a coroutine, which can be paused and resumed without blocking threads.
20. Which tool is best for debugging layout issues visually?
A. Logcat
B. Lint
C. Layout Inspector
D. Firebase Analytics
Answer: C
Explanation: Layout Inspector provides a real-time view of the app’s UI hierarchy for layout debugging.
21. What is Parcelable
used for in Android?
A. Store preferences
B. Serialize objects to pass between components
C. Display notifications
D. Format layouts
Answer: B
Explanation: Parcelable
is an interface used to serialize data so it can be passed through Intents or Bundles.
22. Which class handles network calls in Retrofit?
A. Request
B. Callback
C. Call<T>
D. AsyncTask
Answer: C
Explanation: In Retrofit, Call<T>
is used to represent HTTP requests and responses.
23. What is a common cause of a NullPointerException
in Android?
A. Using a fragment
B. Declaring a val
C. Accessing an uninitialized object
D. Using a coroutine
Answer: C
Explanation: Accessing null or uninitialized references results in a NullPointerException
.
24. Which class allows backstack operations with Fragments?
A. FragmentTransaction
B. ActivityManager
C. FragmentFactory
D. IntentManager
Answer: A
Explanation: FragmentTransaction
allows you to add, replace, and remove fragments and manage the back stack.
25. Which folder contains app UI layouts?
A. res/raw
B. res/layout
C. src/java
D. res/drawable
Answer: B
Explanation: XML layout files go in the res/layout
directory.
26. Which data type is used in LiveData
?
A. MutableLiveData<T>
B. Flow<T>
C. Observable<T>
D. Single<T>
Answer: A
Explanation: MutableLiveData<T>
is a LiveData object that allows changes to its value.
27. What is the purpose of @HiltAndroidApp
in Dagger Hilt?
A. Configure navigation
B. Set default font
C. Initialize dependency injection
D. Handle image caching
Answer: C
Explanation: @HiltAndroidApp
sets up the application for Hilt-based dependency injection.
28. Which method releases system resources in an Activity?
A. onStart()
B. onResume()
C. onDestroy()
D. onCreate()
Answer: C
Explanation: onDestroy()
is called when an Activity is finishing and should be used to clean up resources.
29. Which XML attribute sets the width of a View to match its parent?
A. android:layout_width="wrap_parent"
B. android:layout_width="fill"
C. android:layout_width="match_parent"
D. android:width="100%"
Answer: C
Explanation: match_parent
tells the view to expand to the width of its parent container.
30. What is the purpose of DataBindingUtil.setContentView()
?
A. Sets a layout without inflation
B. Enables direct access to views in layout XML
C. Connects layouts with ViewModel
D. Initializes RecyclerView
Answer: B
Explanation: This method allows binding layouts to activity code and accessing views directly without findViewById
.
Reviews
There are no reviews yet.