Sample questions
Question 1Easy
In Hilt, which annotation goes on the Application class?
- @HiltAndroidApp
- @Module
- @HiltViewModel
- @AndroidEntryPoint
Answer: A. @HiltAndroidApp
Explanation
It triggers Hilt's code generation and the application-level component.
Step-by-step solution
- @HiltAndroidApp goes on the Application subclass.
- It triggers Hilt's code generation and the app-level container.
- Other Android classes then use @AndroidEntryPoint.
Why the other options are wrong
- B. @Module marks classes that provide bindings.
- C. @HiltViewModel marks ViewModels.
- D. @AndroidEntryPoint is for Activities, Fragments and similar.
Question 2Easy
An Android ViewModel is designed to:
- Replace the Activity
- Draw views on the screen
- Store data permanently on disk
- Hold UI state across rotation
Answer: D. Hold UI state across rotation
Explanation
A ViewModel outlives Activity recreation (e.g. rotation) and is cleared when its owner is finished.
Step-by-step solution
- Rotation destroys and recreates the Activity.
- A ViewModel lives in a ViewModelStore that survives this.
- So UI state is kept across configuration changes.
Why the other options are wrong
- A. The Activity is still needed.
- B. The UI layer draws views.
- C. ViewModels are in memory, not on disk.
Question 3Easy
In MVVM on Android, the View layer is typically:
- The UI code
- The Repository
- The REST API
- The Room database
Answer: A. The UI code
Explanation
The View renders state from the ViewModel and forwards user events.
Step-by-step solution
- MVVM = Model, View, ViewModel.
- The View is the UI: Activities, Fragments or composables.
- It renders state and forwards user events.
Why the other options are wrong
- B. The Repository is part of the data layer.
- C. REST APIs are data sources.
- D. Room is a data source.
Question 4Easy
- Model-Version-View-Manager
- Main-View-Visual-Model
- Model-View-ViewModel
- Modular View Verification Method
Answer: C. Model-View-ViewModel
Explanation
The ViewModel exposes state that the View observes.
Step-by-step solution
- MVVM splits an app into three layers.
- Model: data and business logic.
- View: the UI. ViewModel: holds UI state and exposes it to the View.
Why the other options are wrong
- A. 'Version' and 'Manager' are not parts of MVVM.
- B. These words are made up.
- D. Not an architecture pattern.
Tip: MVVM: View observes, ViewModel exposes, Model provides.
Question 5Medium
How does a Hilt-injected ViewModel receive its dependencies?
- Using reflection at runtime only
- Through setter methods called by the Activity
- @HiltViewModel plus an @Inject constructor
- From a static singleton
Answer: C. @HiltViewModel plus an @Inject constructor
Explanation
In Compose it is obtained with hiltViewModel(); in Activities with by viewModels().
Step-by-step solution
- Annotate the ViewModel class with @HiltViewModel.
- Mark its constructor with @Inject and list the dependencies.
- Get it with by viewModels() in an @AndroidEntryPoint screen or hiltViewModel() in Compose.
Why the other options are wrong
- A. Hilt generates code at compile time; it does not rely on runtime reflection.
- B. Constructor injection is the Hilt way.
- D. Statics bypass DI.
Question 6Medium
In the recommended app architecture, the Repository's role is to:
- Render UI components
- Define navigation routes
- Mediate data sources
- Handle permissions
Answer: C. Mediate data sources
Explanation
Repositories combine network and local database sources and expose data to ViewModels.
Step-by-step solution
- The data layer may have several sources: network, database, cache.
- The Repository hides them behind one interface.
- It decides where to read from and keeps sources in sync.
Why the other options are wrong
- A. Rendering is the UI's job.
- B. Navigation belongs to the UI layer.
- D. Permissions belong to the UI layer.
Question 7Medium
Which method of a ViewModel is called just before it is destroyed?
onCleared()finish()onStop()onDestroy()
Answer: A. onCleared()
Explanation
Use it to release resources; viewModelScope is cancelled at this point.
Step-by-step solution
- A ViewModel lives until its owner is finished for good.
- Just before it is destroyed, onCleared() is called.
- Use it to cancel work and release resources; viewModelScope is cancelled automatically.
Why the other options are wrong
- B. finish() is an Activity method.
- C. onStop() is an Activity lifecycle callback.
- D. onDestroy() belongs to Activities and Fragments, not ViewModels.
Tip: ViewModel end = onCleared().
Question 8Medium
AndroidViewModel differs from ViewModel because it:
- Can hold an Activity safely
- Survives process death
- Runs on a background thread
- Gets the Application
Answer: D. Gets the Application
Explanation
The Application context is safe to hold because it lives as long as the app.
Step-by-step solution
- AndroidViewModel takes an Application in its constructor.
- That gives it a context that lives as long as the app.
- So it is safe to keep, unlike an Activity context.
Why the other options are wrong
- A. Holding an Activity leaks in any ViewModel.
- B. It does not survive process death.
- C. Threading is unrelated.
Question 9Hard
A screen shows Loading, Success(data) or Error(message). Which Kotlin construct models this best?
- A String status field
- An Int with magic numbers
- A sealed interface UiState
- Three separate Boolean flags
Answer: C. A sealed interface UiState
Explanation
Sealed types make impossible combinations unrepresentable and give exhaustive when checks.
Step-by-step solution
- The three states are mutually exclusive.
- A sealed interface with Loading, Success(data) and Error(message) models exactly that.
- when then handles each case, checked by the compiler.
Why the other options are wrong
- A. Strings are easy to mistype and cannot carry typed data.
- B. Magic numbers are unclear and unchecked.
- D. Booleans allow impossible combinations, like loading and error at once.
Question 10Hard
In the recommended architecture, the optional domain layer usually contains:
- Use cases
- Room entities only
- XML layout files
- Compose themes
Answer: A. Use cases
Explanation
Use cases (interactors) sit between ViewModels and repositories when logic is shared or complex.
Step-by-step solution
- The domain layer sits between UI and data.
- It holds use cases (interactors).
- Each use case wraps one piece of business logic, often combining repositories.
Why the other options are wrong
- B. Room entities belong in the data layer.
- C. Layouts are UI.
- D. Themes are UI.
Practise all 17 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →