Preparing for a Senior Android Engineer interview requires a solid understanding of Android technologies, frameworks, and practices. Here are 10 potential questions and answers for each topic you mentioned:
1. Kotlin
-
Q: What are extension functions in Kotlin, and how are they used?
A: Extension functions allow adding new functionality to existing classes without modifying their code. They’re defined with a receiver type and used like a regular member function.
Example:fun String.removeWhitespace() = this.replace(" ", "")
-
Q: What is the difference between
var
andval
?
A:val
is read-only and immutable once initialized, whilevar
is mutable and can be reassigned. -
Q: Explain Kotlin's null safety features.
A: Kotlin uses nullable types (e.g.,String?
) and operators (?.
,!!
,?:
) to minimize null pointer exceptions. -
Q: What are higher-order functions in Kotlin?
A: Functions that take other functions as parameters or return them. -
Q: Describe Kotlin's sealed classes.
A: Sealed classes represent restricted hierarchies and allow exhaustive when-checks. -
Q: How does
data class
differ from a regular class?
A: Data classes provide default implementations forequals()
,hashCode()
, andtoString()
. -
Q: What is the purpose of
companion object
?
A: It acts as a static equivalent for class members. -
Q: How do you use
inline
functions, and why?
A: Inline functions prevent function call overhead by replacing the function call with its body at compile time. -
Q: What is a lambda expression in Kotlin?
A: It’s a short, unnamed function defined using the{}
syntax. -
Q: Explain
by lazy
in Kotlin.
A: It initializes a property only when it’s accessed for the first time.
2. Coroutines
-
Q: What are coroutines in Kotlin?
A: Coroutines are a lightweight, concurrency framework for managing asynchronous tasks. -
Q: What’s the difference between
launch
andasync
?
A:launch
returns aJob
, whileasync
returns aDeferred
which can provide results viaawait()
. -
Q: How does
suspend
function work?
A: It’s a function that can suspend execution without blocking the thread. -
Q: Explain the difference between
runBlocking
andCoroutineScope
.
A:runBlocking
blocks the thread, whileCoroutineScope
does not. -
Q: What is a
CoroutineScope
?
A: A scope defines the lifecycle of coroutines launched within it. -
Q: What is the purpose of
Dispatchers
in coroutines?
A: Dispatchers determine the thread pool used (e.g.,Main
,IO
,Default
). -
Q: Explain structured concurrency.
A: It ensures that coroutines are launched in a structured way, tied to a scope, and complete predictably. -
Q: How does
withContext
differ fromlaunch
?
A:withContext
switches context and waits for the result;launch
launches a new coroutine. -
Q: What are
Flow
and its advantages over RxJava?
A:Flow
is a Kotlin-native solution for handling streams of data asynchronously. It integrates better with coroutines and has less overhead. -
Q: How do you handle exceptions in coroutines?
A: Usingtry-catch
blocks orCoroutineExceptionHandler
.
3. Compose
-
Q: What is Jetpack Compose?
A: It’s Android’s modern UI toolkit for building native UI declaratively. -
Q: Explain the
@Composable
annotation.
A: Marks a function as composable, meaning it can define UI in a declarative manner. -
Q: How does state management work in Compose?
A: Usingremember
,mutableStateOf
, andState
classes. -
Q: What is
remember
in Compose?
A: It retains state across recompositions. -
Q: How do you create a list in Compose?
A: UsingLazyColumn
orLazyRow
. -
Q: What is the difference between
Modifier
andLayoutModifier
?
A:Modifier
allows UI transformations;LayoutModifier
deals specifically with layout constraints. -
Q: How do you handle themes in Compose?
A: UsingMaterialTheme
and customTheme
composables. -
Q: Explain
SideEffect
in Compose.
A: Executes code whenever there’s a recomposition. -
Q: What is recomposition?
A: The process of redrawing the UI when state changes. -
Q: How does navigation work in Compose?
A: UsingNavHost
andNavController
.
4. MVVM
-
Q: What is MVVM?
A: Model-View-ViewModel, a design pattern to separate UI from business logic. -
Q: Why is MVVM preferred in Android?
A: It provides a clear separation of concerns and makes UI testing easier. -
Q: How does LiveData fit into MVVM?
A: It observes and reacts to changes in data, driving UI updates. -
Q: What is the role of ViewModel?
A: It handles business logic and prepares data for the UI. -
Q: What are common pitfalls in MVVM?
A: Overloading ViewModel with UI logic, improper lifecycle management. -
Q: How do you test ViewModel?
A: Using unit tests with mocking frameworks like Mockito. -
Q: Explain the role of Repository in MVVM.
A: It abstracts data sources and manages operations like caching and remote API calls. -
Q: How does Hilt assist in MVVM?
A: By providing dependency injection for ViewModel and other components. -
Q: How does Coroutines improve MVVM?
A: It enables asynchronous calls within ViewModel usingviewModelScope
. -
Q: What’s the difference between MVVM and MVC?
A: In MVVM, the ViewModel communicates directly with the View, unlike the Controller in MVC.
5. Retrofit
-
Q: What is Retrofit, and why is it used?
A: Retrofit is a type-safe HTTP client for Android and Java, used for API calls and parsing responses. -
Q: How do you define a Retrofit API interface?
A: Using annotations like@GET
,@POST
, and methods returningCall
,Deferred
, orFlow
.
Example:@GET("users/{id}") suspend fun getUser(@Path("id") userId: Int): User
-
Q: What is the purpose of
@Query
annotation?
A: It appends query parameters to the URL.
Example:@GET("search") suspend fun searchUsers(@Query("name") name: String): List<User>
-
Q: How do you handle JSON responses with Retrofit?
A: By using converters likeGsonConverterFactory
orMoshiConverterFactory
. -
Q: How can you cancel a Retrofit request?
A: UseCall.cancel()
or ensure proper coroutine scope cancellation when usingsuspend
. -
Q: What are interceptors in Retrofit?
A: Interceptors (via OkHttp) are used for logging, adding headers, or handling authentication. -
Q: How do you handle API errors in Retrofit?
A: By checking the response code and parsing the error body if needed. -
Q: What is
enqueue
in Retrofit?
A: It performs an asynchronous call and handles success or failure in a callback. -
Q: How do you add dynamic headers to a Retrofit request?
A: Use@Header
annotation or an interceptor. -
Q: What’s the difference between
Call
andsuspend
in Retrofit?
A:Call
is used for synchronous or asynchronous calls, whilesuspend
integrates better with coroutines for cleaner, asynchronous API usage.
6. Dependency Injection (Hilt)
-
Q: What is Hilt, and why is it used?
A: Hilt is a dependency injection library for Android, simplifying Dagger integration. -
Q: What is the role of
@HiltAndroidApp
?
A: It sets up Hilt for the entire app and generates a base class for dependency injection. -
Q: What is a
Module
in Hilt?
A: A class annotated with@Module
that provides dependencies using@Provides
or@Binds
. -
Q: How do you inject dependencies in a ViewModel using Hilt?
A: By annotating the ViewModel with@HiltViewModel
and using constructor injection. -
Q: Explain the use of
@Singleton
in Hilt.
A: It ensures a single instance of a dependency is used throughout the app lifecycle. -
Q: What is
@EntryPoint
in Hilt?
A: It allows dependency injection in classes not directly supported by Hilt (e.g., BroadcastReceiver). -
Q: How does Hilt handle activity and fragment-scoped dependencies?
A: Using annotations like@ActivityScoped
and@FragmentScoped
. -
Q: What’s the difference between
@Provides
and@Binds
?
A:@Provides
creates an instance, while@Binds
maps an interface to an implementation. -
Q: How do you test classes using Hilt?
A: Use theHiltAndroidRule
and@BindValue
for dependency overrides in tests. -
Q: What are the benefits of using Hilt over manual DI or Service Locator patterns?
A: Simplifies setup, improves testability, ensures lifecycle-awareness, and reduces boilerplate.
7. Jetpack Architecture Components
-
Q: What are Jetpack Architecture Components?
A: A collection of libraries to implement modern Android app architecture, like LiveData, ViewModel, Room, etc. -
Q: How does
LiveData
work?
A: It observes data changes and updates the UI reactively. -
Q: What is the role of the
ViewModel
in Jetpack?
A: To manage UI-related data in a lifecycle-aware manner. -
Q: What is
Room
, and how is it used?
A: Room is a SQLite abstraction library that provides type-safe database interactions. -
Q: How do you observe
LiveData
in an Activity or Fragment?
A: Using theobserve
method.
Example:viewModel.data.observe(this) { data -> /* Update UI */ }
-
Q: What is
DataStore
, and how is it different fromSharedPreferences
?
A:DataStore
is a modern and more robust solution for key-value storage, using Coroutines. -
Q: How does
Paging
help in Jetpack?
A: It loads data gradually, reducing resource usage. -
Q: What is
WorkManager
?
A: A library to schedule and manage deferrable, guaranteed background work. -
Q: How do you implement lifecycle-aware components?
A: By usingLifecycleObserver
orLifecycleOwner
. -
Q: What’s the purpose of
SavedStateHandle
in Jetpack?
A: To save and restore UI state across configuration changes.
8. GSON
-
Q: What is GSON?
A: A library to convert Java/Kotlin objects to JSON and vice versa. -
Q: How do you deserialize JSON using GSON?
A: UsingGson().fromJson(jsonString, MyClass::class.java)
. -
Q: What is the difference between
@SerializedName
and a regular field?
A:@SerializedName
maps JSON keys to class properties. -
Q: Can GSON handle nested JSON?
A: Yes, by mapping nested objects to corresponding classes. -
Q: How do you handle unknown fields in JSON with GSON?
A: UseJsonElement
or custom deserializers. -
Q: What is a
TypeToken
in GSON?
A: It helps deserialize generic types likeList<T>
. -
Q: How do you serialize Kotlin data classes with default values?
A: Use the default GSON configuration, or customize the serialization policy. -
Q: How do you configure GSON to exclude null values?
A: UseGsonBuilder().serializeNulls()
to include or exclude nulls. -
Q: What is a custom serializer in GSON?
A: A class that implementsJsonSerializer
orJsonDeserializer
to define custom logic. -
Q: How does GSON handle arrays and lists?
A: Automatically maps JSON arrays to Kotlin/Java lists.
9. Test-Driven Development (TDD)
-
Q: What is TDD?
A: A development methodology where tests are written before writing the actual code. -
Q: What are the main benefits of TDD?
A: Improved code quality, fewer bugs, and easier refactoring. -
Q: How does TDD differ from traditional testing?
A: Tests guide code implementation instead of verifying existing code. -
Q: What is a red-green-refactor cycle in TDD?
A: Write a failing test (red), make it pass (green), and refactor for optimization. -
Q: How do you write a unit test for ViewModel?
A: Mock dependencies and verify the outputs using assertions. -
Q: What is the role of mocking in TDD?
A: It isolates the unit being tested by simulating dependencies. -
Q: How do you ensure code coverage in TDD?
A: By writing comprehensive tests for all possible scenarios. -
Q: What tools can you use for TDD in Android?
A: JUnit, Mockito, Espresso, Robolectric. -
Q: How does TDD integrate with Agile?
A: It fits naturally into Agile’s iterative and incremental development approach. -
Q: What are common pitfalls of TDD?
A: Over-testing, slow development pace, and poorly written tests.
10. CI/CD (Continuous Integration and Continuous Deployment)
-
Q: What is CI/CD, and why is it important?
A: CI/CD automates the integration, testing, and deployment processes, ensuring faster delivery and better quality. -
Q: What tools are commonly used for CI/CD in Android development?
A: Jenkins, GitHub Actions, Bitrise, CircleCI, Travis CI. -
Q: How do you set up a CI/CD pipeline for an Android project?
A: Use a CI/CD tool to automate build, run tests, and deploy APK to a distribution service (e.g., Firebase App Distribution). -
Q: What is the purpose of build.gradle files in CI/CD?
A: They define how the project is built, including dependencies, plugins, and configurations. -
Q: How do you implement versioning in a CI/CD pipeline?
A: Use scripts to increment versionCode and versionName dynamically during the build process. -
Q: How do you run UI tests in CI/CD pipelines?
A: Use frameworks like Espresso or UIAutomator, triggered by the CI/CD tool. -
Q: What is a release pipeline, and how does it differ from a build pipeline?
A: A release pipeline automates deployment to production, while a build pipeline focuses on compiling and testing. -
Q: How do you ensure security in CI/CD pipelines?
A: Use secure credentials management, encrypt API keys, and limit access to pipelines. -
Q: What is trunk-based development, and how does it relate to CI/CD?
A: It involves frequent merging of small changes into a shared mainline, ensuring a smooth CI/CD process. -
Q: How do you integrate Firebase Crashlytics into a CI/CD pipeline?
A: Use Firebase CLI to upload dSYM or mapping files during the build process.
11. Design Patterns
-
Q: What are design patterns, and why are they important in Android development?
A: They are reusable solutions to common problems, ensuring cleaner, maintainable, and scalable code. -
Q: Explain the MVVM pattern.
A: It separates the UI (View), business logic (ViewModel), and data source (Model) for better code management. -
Q: What is the Singleton pattern, and where is it used in Android?
A: It ensures only one instance of a class exists; used in dependency injection or managing resources. -
Q: How does the Observer pattern work in Android?
A: Used by LiveData, it notifies observers when data changes. -
Q: What is the Factory pattern?
A: A pattern that creates objects without exposing the instantiation logic. -
Q: How does the Builder pattern work in Android?
A: Simplifies object creation by providing a step-by-step construction process, e.g.,AlertDialog.Builder
. -
Q: What is the Repository pattern in MVVM?
A: It abstracts data sources (network, database) from the ViewModel. -
Q: How does the Adapter pattern apply in Android?
A: It bridges the gap between data and UI components, e.g.,RecyclerView.Adapter
. -
Q: Explain the Strategy pattern.
A: It defines a family of algorithms, encapsulates each one, and makes them interchangeable. -
Q: What is the Decorator pattern, and where is it used?
A: It adds new functionality to objects dynamically; e.g., chaining operations withOkHttp
interceptors.
12. Flow
-
Q: What is Flow in Kotlin?
A: A cold asynchronous stream that emits values sequentially. -
Q: How does Flow differ from LiveData?
A: Flow is coroutine-based and supports more operators, while LiveData is lifecycle-aware. -
Q: What are the types of Flows in Kotlin?
A:Flow
,StateFlow
, andSharedFlow
. -
Q: What is the purpose of
collect()
in Flow?
A: It consumes emitted values from a Flow. -
Q: How do you handle exceptions in a Flow?
A: Use operators likecatch
oronCompletion
. -
Q: What is
StateFlow
?
A: A state-holder observable that always holds the latest value and emits updates. -
Q: How do you debounce API calls using Flow?
A: Use thedebounce()
operator to delay emissions. -
Q: How do you transform data in a Flow?
A: Use operators likemap
,flatMapConcat
, orfilter
. -
Q: What is
combine()
in Flow?
A: It merges multiple flows into one by combining their emissions. -
Q: How do you convert Flow into LiveData?
A: Use theasLiveData()
extension function.
13. Agile Methodology
-
Q: What is Agile methodology?
A: An iterative and incremental approach to software development focusing on flexibility and collaboration. -
Q: What are the core principles of Agile?
A: Customer satisfaction, welcoming changes, frequent delivery, and teamwork. -
Q: What is the role of a sprint in Agile?
A: A time-boxed iteration where the team delivers a potentially shippable product increment. -
Q: What is a Scrum Master?
A: A facilitator who ensures the Agile process runs smoothly and removes impediments. -
Q: What are the differences between Scrum and Kanban?
A: Scrum is sprint-based, while Kanban focuses on continuous flow without time constraints. -
Q: What is a Product Backlog?
A: A prioritized list of tasks or features for the team to work on. -
Q: What is the purpose of a daily stand-up?
A: To synchronize team activities, discuss progress, and identify roadblocks. -
Q: How do you handle changes to requirements during a sprint?
A: Changes are minimized in a sprint, but they can be added to the backlog for future sprints. -
Q: What is a retrospective meeting?
A: A meeting to reflect on what went well, what didn’t, and how to improve. -
Q: How do you measure success in Agile?
A: By delivering working software frequently, team collaboration, and customer satisfaction.
14. Kotlin Coroutines
-
Q: What is a coroutine in Kotlin?
A: A lightweight thread that provides concurrency without blocking the main thread. -
Q: How do you start a coroutine in Kotlin?
A: Usinglaunch
,async
, orrunBlocking
builders within aCoroutineScope
. -
Q: What is the difference between
launch
andasync
?
A:launch
returns aJob
and does not return a result, whileasync
returns aDeferred
and is used for obtaining a result. -
Q: What are
suspend
functions?
A: Functions that can be paused and resumed, making them ideal for asynchronous programming. -
Q: What is
CoroutineScope
?
A: A lifecycle-bound scope that manages the coroutines within it. -
Q: How do you handle exceptions in coroutines?
A: Usingtry-catch
blocks orCoroutineExceptionHandler
. -
Q: What is the difference between
withContext
andlaunch
?
A:withContext
switches the context and waits for execution to complete, whereaslaunch
starts a new coroutine. -
Q: What is
Dispatchers
in coroutines?
A: Dispatchers likeMain
,IO
, andDefault
determine the thread on which a coroutine runs. -
Q: Explain structured concurrency in Kotlin Coroutines.
A: Ensures all coroutines are completed or canceled when their parent scope ends. -
Q: How do you use
flowOn
in coroutines?
A: To change the dispatcher for a Flow without affecting downstream operations.
15. Android Jetpack Compose
-
Q: What is Jetpack Compose?
A: A modern, declarative UI toolkit for building Android user interfaces. -
Q: How does Compose differ from the traditional View system?
A: Compose uses a reactive programming model and eliminates the need for XML layouts. -
Q: What is a
Composable
function?
A: A function annotated with@Composable
that defines UI components. -
Q: How do you manage state in Jetpack Compose?
A: Usingremember
andmutableStateOf
for local state, orState
andViewModel
for shared state. -
Q: What is
LaunchedEffect
in Jetpack Compose?
A: A composable function that runs a block of code once when the key changes. -
Q: How do you handle navigation in Jetpack Compose?
A: Using theNavHost
andNavController
from theNavigation Compose
library. -
Q: What is the role of
Modifier
in Compose?
A: To modify UI elements' layout, behavior, and appearance. -
Q: How does recomposition work in Jetpack Compose?
A: It updates only the parts of the UI tree where state has changed. -
Q: What is
SideEffect
in Compose?
A: A composable function that performs non-composable side effects when recomposition occurs. -
Q: How do you test Jetpack Compose UIs?
A: UsingComposeTestRule
andSemantics
to write UI tests.
16. Test-Driven Development (TDD)
-
Q: What is Test-Driven Development?
A: A methodology where tests are written before writing the actual code. -
Q: What are the benefits of TDD?
A: Improved code quality, fewer bugs, and better design. -
Q: How do you write a unit test for a ViewModel in TDD?
A: Mock dependencies usingMockito
and write tests usingJUnit
to validate the ViewModel’s behavior. -
Q: What are mocks and stubs?
A: Mocks simulate objects for testing interactions, while stubs return predefined data for testing methods. -
Q: How do you write a failing test in TDD?
A: Write a test case for functionality that hasn't been implemented yet. -
Q: What is the red-green-refactor cycle in TDD?
A: Red: Write a failing test. Green: Write code to pass the test. Refactor: Optimize the code. -
Q: How do you mock network responses in TDD?
A: Use libraries likeMockWebServer
or create custom fake repositories. -
Q: How is TDD applied to UI testing?
A: Write UI tests usingEspresso
orCompose Test
before implementing the UI components. -
Q: How do you ensure code coverage in TDD?
A: By writing tests for all use cases and validating using tools likeJaCoCo
. -
Q: What challenges are common in TDD, and how do you overcome them?
A: Writing tests for complex scenarios; use dependency injection and mocks.
17. Android Jetpack Architecture Components
-
Q: What are Android Jetpack components?
A: A set of libraries for building Android applications faster and easier. -
Q: What is the purpose of the
Lifecycle
component?
A: It helps manage UI components' lifecycle-aware behavior, like LiveData. -
Q: Explain
LiveData
and its use cases.
A: A lifecycle-aware observable that updates the UI when data changes. -
Q: What is a
ViewModel
in Android?
A: A component that stores UI-related data to survive configuration changes. -
Q: How does the
Navigation
component help in Android development?
A: It simplifies navigation and deep linking, reducing boilerplate code. -
Q: What is
DataStore
in Jetpack?
A: A library for storing key-value pairs or typed objects using Kotlin Coroutines. -
Q: What is
Paging
in Jetpack?
A: A library for loading and displaying data incrementally in RecyclerView. -
Q: How does
WorkManager
differ fromJobScheduler
?
A:WorkManager
is more flexible, supporting both immediate and deferred background tasks. -
Q: What is the
Room
database?
A: A persistence library that provides an abstraction over SQLite for easier database access. -
Q: How does
Hilt
simplify dependency injection?
A: It generates and provides bindings for Android classes, reducing boilerplate.
18. REST API and Networking
-
Q: What is a REST API?
A: REST (Representational State Transfer) API is a web service that uses HTTP methods (GET, POST, PUT, DELETE) to perform CRUD operations on resources. -
Q: How do you integrate a REST API in an Android app?
A: By using libraries likeRetrofit
orVolley
for HTTP requests and GSON or Moshi for parsing JSON responses. -
Q: What is the purpose of an API response code?
A: It indicates the status of an HTTP request (e.g.,200 OK
,404 Not Found
,500 Internal Server Error
). -
Q: How do you handle API errors in an Android app?
A: By implementing error-handling mechanisms usingtry-catch
,Retrofit
interceptors, and parsing error response bodies. -
Q: What is the difference between synchronous and asynchronous API calls?
A: Synchronous calls block the thread until completion, while asynchronous calls allow the thread to continue execution. -
Q: How do you optimize network calls in Android?
A: By caching responses, using pagination, minimizing payload sizes, and leveraging efficient libraries likeRetrofit
withOkHttp
. -
Q: What is an interceptor in Retrofit?
A: It is a mechanism to intercept and modify requests or responses before they reach the server or client. -
Q: How do you handle token-based authentication in API calls?
A: By including the token in theAuthorization
header of HTTP requests and refreshing expired tokens. -
Q: What is the role of
@SerializedName
in GSON?
A: It maps JSON keys to Kotlin/Java object fields during serialization/deserialization. -
Q: How do you test API calls in Android?
A: By using tools likePostman
for manual testing and libraries likeMockWebServer
for unit tests.
19. GSON and JSON Parsing
-
Q: What is GSON, and how is it used in Android?
A: GSON is a Java library for converting JSON to Java/Kotlin objects and vice versa. -
Q: How do you parse a JSON response using GSON?
A: By creating a data class matching the JSON structure and usingGson().fromJson()
to parse. -
Q: How do you handle nested JSON objects with GSON?
A: By creating corresponding nested data classes. -
Q: How do you convert a Kotlin object to a JSON string?
A: By usingGson().toJson()
. -
Q: What is the purpose of the
@Expose
annotation in GSON?
A: To include/exclude fields during serialization/deserialization. -
Q: How do you deserialize a JSON array in GSON?
A: By usingTypeToken
to specify the type of the list. -
Q: What is the difference between
JsonElement
andJsonObject
in GSON?
A:JsonElement
represents any JSON type, whileJsonObject
represents a JSON object specifically. -
Q: How do you handle unknown or dynamic JSON fields in GSON?
A: By usingJsonObject
or aMap<String, Any>
. -
Q: Can GSON handle custom deserialization?
A: Yes, by implementing a customJsonDeserializer
. -
Q: How do you handle optional or nullable fields in GSON?
A: By using Kotlin'snullable
types or default values.
20. Android Security
-
Q: What are the best practices for securing sensitive data in an Android app?
A: UseEncryptedSharedPreferences
, the Android Keystore system, and avoid hardcoding sensitive data. -
Q: How do you secure API keys in Android?
A: By storing them in thelocal.properties
file or using secure backend services. -
Q: What is ProGuard, and how does it enhance app security?
A: ProGuard is a tool that obfuscates code, making it harder to reverse-engineer. -
Q: How do you secure network communication in an Android app?
A: By using HTTPS, certificate pinning, and secure libraries likeRetrofit
orOkHttp
. -
Q: What is the role of permissions in Android security?
A: Permissions regulate access to sensitive data and system features. -
Q: How do you implement biometric authentication in Android?
A: Using theBiometricPrompt
API. -
Q: What is an
intent-filter
vulnerability, and how can it be prevented?
A: It occurs when unprotected components are exposed; prevent it by declaringandroid:exported=false
. -
Q: How do you prevent SQL injection in SQLite?
A: By using parameterized queries or ORM libraries likeRoom
. -
Q: What is the Android Keystore system?
A: A secure container for cryptographic keys that cannot be extracted. -
Q: How do you implement encryption in Android?
A: By using libraries likeCipher
for symmetric encryption orKeyPairGenerator
for asymmetric encryption.
21. Performance Optimization
-
Q: How do you improve UI performance in Android?
A: By optimizing layouts, reducing overdraw, and avoiding blocking the main thread. -
Q: What tools do you use to monitor app performance?
A: Android Studio Profiler, Firebase Performance Monitoring, and Systrace. -
Q: How do you reduce app launch time?
A: By optimizing the splash screen, preloading resources, and deferring initialization of heavy components. -
Q: What is overdraw, and how do you fix it?
A: Overdraw occurs when a UI element is drawn multiple times; fix it by simplifying layouts and usingLAYER_TYPE_NONE
. -
Q: How do you optimize RecyclerView performance?
A: By usingDiffUtil
,ViewHolder
, and enablingsetHasFixedSize
. -
Q: How do you detect memory leaks in an Android app?
A: By using tools likeLeakCanary
or Android Profiler. -
Q: What are the best practices for handling large bitmaps in Android?
A: By usingBitmapFactory.Options
for scaling and loading in smaller resolutions. -
Q: How do you improve battery efficiency in Android apps?
A: By minimizing background work, usingWorkManager
, and batching network requests. -
Q: How do you reduce APK size?
A: By enabling code shrinking with R8, removing unused resources, and using vector drawables. -
Q: How do you optimize database operations in Android?
A: By using indexing, caching queries, and keeping the database schema simple.
22. Multi-Module Architecture
-
Q: What is multi-module architecture in Android?
A: It's a project structure that divides an app into multiple modules, promoting reusability, faster build times, and modularized code. -
Q: What types of modules can you create in an Android project?
A:App Module
,Feature Module
,Library Module
, andDynamic Feature Module
. -
Q: What are the benefits of modularizing an Android app?
A: Improved scalability, reduced build times, parallel development, and easier testing. -
Q: How do you manage dependencies across multiple modules?
A: By using a centralizedbuildSrc
or Gradle'sversion catalog
for dependency management. -
Q: How do you enable communication between modules?
A: Through interfaces, dependency injection (like Hilt), or Navigation Component for navigation. -
Q: What is a dynamic feature module?
A: A module that allows specific features to be downloaded on demand using Play Feature Delivery. -
Q: What is the role of the base module in a multi-module project?
A: It contains shared resources like networking, database, and core utilities. -
Q: How do you structure packages in a feature module?
A: By following clean architecture layers likedata
,domain
, andpresentation
. -
Q: What challenges arise with multi-module architecture?
A: Managing dependencies, increased complexity, and potential code duplication without careful planning. -
Q: How do you test individual modules in a multi-module app?
A: By writing unit tests for each module and integration tests to test communication between modules.
23. Android Jetpack Libraries
-
Q: What is Android Jetpack?
A: A collection of libraries, tools, and architectural guidance to accelerate Android app development. -
Q: Name some popular Android Jetpack libraries.
A: Room, WorkManager, Navigation, LiveData, ViewModel, DataStore, Paging. -
Q: How does the Navigation Component simplify navigation?
A: By providing a single source of truth for navigation and handling back stack management. -
Q: What is the role of WorkManager in Android?
A: To schedule deferrable and guaranteed background tasks. -
Q: How do you use Room for database management?
A: By defining entities, DAOs, and a database class annotated with@Database
. -
Q: What is LiveData, and how does it work?
A: LiveData is a lifecycle-aware observable data holder that updates UI components when data changes. -
Q: How does the Paging library help with large datasets?
A: By loading data incrementally, reducing memory usage and improving performance. -
Q: What is DataStore, and how is it different from SharedPreferences?
A: DataStore is a modern solution for data storage using Kotlin Coroutines and Flow, offering better performance and type safety. -
Q: How do you implement a ViewModel in Jetpack?
A: By extending theViewModel
class and providing data to the UI using LiveData or Flow. -
Q: What are the advantages of using Jetpack Compose over XML?
A: Faster UI development, declarative syntax, better state management, and integration with Kotlin.
24. Advanced Dependency Injection
-
Q: What is dependency injection?
A: A design pattern where dependencies are provided rather than hard-coded, improving testability and maintainability. -
Q: Why use Hilt for dependency injection?
A: Hilt simplifies DI setup in Android by providing a pre-defined structure and integrating with Jetpack components. -
Q: What is the difference between
@Singleton
and@ViewModelScoped
in Hilt?
A:@Singleton
creates a single instance for the entire application, while@ViewModelScoped
ties the instance's lifecycle to a ViewModel. -
Q: How do you inject dependencies in a Fragment using Hilt?
A: Annotate the Fragment with@AndroidEntryPoint
and use@Inject
for fields or constructors. -
Q: What is the purpose of a
@Module
in Hilt?
A: To define how dependencies are provided, using@Provides
or@Binds
. -
Q: How do you handle dependencies that require runtime arguments in Hilt?
A: By using assisted injection or passing the argument into a factory class. -
Q: What is the difference between
@Provides
and@Binds
?
A:@Provides
creates an instance of a class, while@Binds
maps an interface to its implementation. -
Q: How do you test Hilt-injected components?
A: By using theHiltAndroidRule
in tests and creating test-specific modules. -
Q: How do you scope a dependency to an Activity or Fragment in Hilt?
A: By using@ActivityScoped
or@FragmentScoped
. -
Q: What is the
@EntryPoint
annotation in Hilt?
A: It allows access to Hilt-generated components outside of Hilt's managed classes.
25. Test-Driven Development (TDD) in Android
-
Q: What is TDD?
A: A software development approach where tests are written before the actual code, ensuring the code meets requirements. -
Q: What are the benefits of TDD in Android development?
A: It improves code quality, ensures reliability, and reduces debugging time. -
Q: What types of tests are typically written in TDD?
A: Unit tests, integration tests, and UI tests. -
Q: How do you write a failing test in TDD?
A: By creating a test case for an unimplemented feature or functionality. -
Q: What is the "Red-Green-Refactor" cycle in TDD?
A: Write a failing test (Red), make it pass (Green), and refactor the code for optimization. -
Q: Which tools are used for TDD in Android?
A: JUnit, Mockito, Espresso, Robolectric. -
Q: How do you test a ViewModel in MVVM architecture?
A: By mocking dependencies and asserting LiveData or Flow outputs. -
Q: How do you handle dependencies in TDD for Android?
A: By using dependency injection frameworks like Hilt or mocking libraries like Mockito. -
Q: What are some challenges in implementing TDD?
A: Initial time investment, complex test cases, and maintaining test coverage. -
Q: How do you measure TDD success in a project?
A: By tracking code coverage, reduced bugs, and consistent delivery of features.
26. Advanced Kotlin Features
-
Q: What are extension functions in Kotlin, and why are they useful?
A: Extension functions add functionality to existing classes without modifying their source code. They are useful for keeping the code clean and reusable. -
Q: What is a
sealed class
in Kotlin, and how does it differ from anenum class
?
A: Asealed class
represents a restricted class hierarchy, where subclasses are known at compile-time. Unlikeenum class
, each subclass of a sealed class can hold different types of data. -
Q: Explain the difference between
inline
,noinline
, andcrossinline
in Kotlin.
A:inline
: Inlines the lambda code into the call site, reducing overhead.noinline
: Prevents the lambda from being inlined.crossinline
: Ensures the lambda doesn’t return directly from the enclosing function.
-
Q: How does
lazy
initialization work in Kotlin?
A:lazy
initializes a property only when it is first accessed. It's thread-safe by default unless specified otherwise. -
Q: What are coroutines'
context
anddispatcher
?
A:context
: Holds metadata about the coroutine (e.g., job, dispatcher).dispatcher
: Determines the thread on which the coroutine runs (Dispatchers.Main
,Dispatchers.IO
).
-
Q: How do you implement delegation in Kotlin?
A: By using theby
keyword. For example, property delegation (val name: String by lazy { "Value" }
). -
Q: What is the difference between
==
and===
in Kotlin?
A:==
checks structural equality, while===
checks referential equality. -
Q: What are inline classes in Kotlin, and when should they be used?
A: Inline classes wrap a value and are used to avoid overhead at runtime, like type wrappers for primitives. -
Q: How do you handle nullable types in Kotlin?
A: By using nullable types (?
), safe calls (?.
), the Elvis operator (?:
), and the not-null assertion operator (!!
). -
Q: Explain the use of higher-order functions in Kotlin.
A: A higher-order function is a function that takes another function as a parameter or returns a function. It allows functional programming constructs likemap
,filter
, andreduce
.
27. Networking and API Handling
-
Q: What is Retrofit, and why is it widely used in Android?
A: Retrofit is a type-safe HTTP client for Android that simplifies API calls by converting JSON responses into Kotlin/Java objects. -
Q: How do you handle network errors in Retrofit?
A: By usingtry-catch
,onFailure
callbacks, or implementing a global error-handling mechanism. -
Q: What are interceptors in OkHttp, and how are they used?
A: Interceptors intercept HTTP requests and responses for logging, modifying headers, or adding authentication tokens. -
Q: How do you cache API responses in Retrofit?
A: By adding a caching layer using OkHttp and setting cache policies in the client. -
Q: Explain the difference between synchronous and asynchronous API calls in Retrofit.
A:- Synchronous calls block the current thread.
- Asynchronous calls execute in the background and use callbacks to return results.
-
Q: How do you implement pagination with Retrofit?
A: By adding query parameters likepage
oroffset
in the API request and handling responses iteratively. -
Q: What is the role of Gson in Retrofit?
A: Gson is used as a converter to serialize and deserialize JSON data. -
Q: How can you use Flow with Retrofit for continuous data streams?
A: By wrapping the API response in aFlow
and collecting it downstream. -
Q: How do you handle SSL pinning in Retrofit?
A: By configuring OkHttp with aCertificatePinner
to validate server certificates. -
Q: What is the advantage of using
Response
wrappers in Retrofit?
A: It provides access to both the API response and metadata like HTTP status codes.
28. Jetpack Compose Advanced Topics
-
Q: What is recomposition in Jetpack Compose?
A: Recomposition is the process where the UI is redrawn when the state changes. -
Q: How do you manage state in Jetpack Compose?
A: Usingremember
,rememberSaveable
, or state management libraries likeStateFlow
andViewModel
. -
Q: What is the difference between
remember
andrememberSaveable
?
A:remember
keeps state only during recomposition, whilerememberSaveable
persists state across configuration changes. -
Q: How do you handle navigation in Jetpack Compose?
A: Using theNavigation
library,NavHost
, andcomposable
routes. -
Q: What are the performance best practices in Jetpack Compose?
A:- Minimize recompositions.
- Use
key
for list items. - Avoid using heavy computations in
Composable
functions.
-
Q: How do you create a custom
Composable
function?
A: By defining a function annotated with@Composable
and using Composable building blocks likeBox
,Row
, andColumn
. -
Q: How does Compose handle accessibility?
A: Usingsemantics
modifiers to describe UI elements for screen readers. -
Q: What is a
Modifier
in Jetpack Compose?
A: AModifier
is a collection of functions that modify the appearance and behavior of a Composable. -
Q: How do you debug Jetpack Compose UIs?
A: UsingDebug inspector
, logging state changes, and theCompose UI Tooling
. -
Q: What are
SideEffects
in Jetpack Compose?
A: They allow you to trigger non-UI operations in response to state changes (LaunchedEffect
,SideEffect
,DisposableEffect
).
29. Kotlin Flow and Reactive Programming
-
Q: What is Kotlin Flow?
A: Flow is a cold stream of asynchronous data used for reactive programming. -
Q: How does Flow differ from LiveData?
A: Flow is coroutine-based and supports more operations like transformations and cancellation. -
Q: What are the three main operators in Flow?
A:emit
: To send data downstream.collect
: To receive and act on the data.transform
: To modify emitted data.
-
Q: How do you handle backpressure in Flow?
A: Flow automatically handles backpressure by suspending the producer until the consumer is ready. -
Q: What is the purpose of
StateFlow
?
A: AStateFlow
emits the latest value and is hot, meaning it stays active even without a collector. -
Q: How do you convert a
LiveData
toFlow
?
A: Using theasFlow()
extension function. -
Q: What is the difference between
StateFlow
andSharedFlow
?
A:StateFlow
holds a single up-to-date value, whileSharedFlow
can emit multiple values to multiple collectors. -
Q: How do you handle exceptions in Flow?
A: By usingcatch
oronCompletion
operators. -
Q: What is
combine
in Flow?
A: It merges multiple flows into a single flow by combining their latest emitted values. -
Q: How do you test Flows in unit tests?
A: By using therunBlockingTest
coroutine scope and asserting emitted values.