Top Interview Questions
Android: A Comprehensive Overview
Android is one of the most widely used operating systems in the world, powering billions of devices globally. Developed by Android Inc., which was later acquired by Google in 2005, Android has become the backbone of mobile computing and has expanded into other devices such as tablets, smart TVs, wearables, and even automobiles. Its open-source nature, coupled with the flexibility it offers developers, has played a significant role in its massive adoption.
Android’s history begins in 2003 when it was founded by Andy Rubin, Rich Miner, Nick Sears, and Chris White with the original vision of creating a smart camera operating system. However, the focus shifted toward mobile phones, recognizing the vast potential of the smartphone market. Google’s acquisition of Android in 2005 enabled the operating system to grow rapidly, leveraging Google’s resources and ecosystem.
The first commercial Android device, the HTC Dream (also known as the T-Mobile G1), was launched in 2008. Since then, Android has undergone continuous evolution, with each version introducing new features, improvements, and performance optimizations. Android versions are often named after desserts or sweet treats, starting with Cupcake, Donut, Éclair, and progressing through versions like Lollipop, Marshmallow, Nougat, Oreo, Pie, and most recently, Android 13 and 14, which focus on privacy, performance, and user experience enhancements.
Android’s architecture is layered, allowing developers to build robust and scalable applications. At a high level, Android consists of four major layers:
Linux Kernel: At the core, Android runs on a modified Linux kernel. The kernel handles fundamental tasks such as memory management, process management, device drivers, and networking. It provides a stable foundation for the Android system and ensures security and resource management.
Hardware Abstraction Layer (HAL): The HAL acts as an intermediary between the hardware and the higher-level system components. It allows Android to communicate with different hardware components such as cameras, sensors, GPS, and audio without requiring developers to write device-specific code.
Android Runtime (ART) and Libraries: ART replaced the older Dalvik Virtual Machine in Android 5.0 Lollipop, providing better performance and memory efficiency. ART executes Android applications written in Java or Kotlin. Android also includes a set of native C/C++ libraries that provide functionalities such as graphics rendering (OpenGL), database management (SQLite), and media playback.
Application Framework and Applications: The application framework provides APIs that developers use to build apps, including access to services like location, telephony, notifications, and UI components. On top of this framework sits the application layer, where apps interact with the user.
Android app development primarily uses Java and Kotlin. Java was the original language for Android, offering a mature and robust platform for application development. Kotlin, officially supported by Google since 2017, is now the preferred language due to its concise syntax, null-safety, and modern features, which reduce common programming errors.
Developers use Android Studio, the official Integrated Development Environment (IDE), to create apps. Android Studio provides a rich set of tools, including code editors, debuggers, emulators, and performance analyzers. It also supports Gradle for build automation, making the development and deployment process streamlined.
An Android application is composed of several components:
Activities: These are screens that users interact with. Each activity is responsible for a single UI and handles user inputs.
Services: Services run in the background without a user interface, performing tasks such as fetching data, playing music, or managing notifications.
Broadcast Receivers: These components respond to system-wide broadcast messages, such as battery low warnings or network connectivity changes.
Content Providers: Content providers manage shared app data, allowing data to be accessed and modified by multiple applications.
These components communicate via Intents, which are messages that facilitate inter-component communication and data transfer.
Android provides numerous features that contribute to its popularity:
Open Source: Android’s open-source nature allows device manufacturers and developers to modify and customize the operating system according to their needs.
Multitasking: Android supports efficient multitasking, enabling users to run multiple apps simultaneously.
Customization: Users can customize home screens, widgets, themes, and notifications extensively.
Google Integration: Android devices benefit from deep integration with Google services like Gmail, Google Maps, Google Drive, and the Google Play Store.
Connectivity: Android supports various connectivity options including Wi-Fi, Bluetooth, NFC, and mobile data.
Security: Android offers robust security features such as app sandboxing, biometric authentication, and regular security updates.
Notifications and Widgets: Android allows rich notifications and interactive widgets, improving user engagement.
The Android ecosystem is vast. The Google Play Store is the primary marketplace for Android apps, hosting millions of apps across categories like social media, gaming, productivity, and finance. Besides smartphones and tablets, Android powers wearables through Wear OS, smart TVs via Android TV, automotive systems via Android Automotive, and even IoT devices through Android Things.
Security is a critical aspect of Android. Google implements several measures:
App Sandbox: Each app runs in its own sandbox, restricting access to system resources and other apps.
Permission Model: Apps must request explicit permissions to access sensitive data like location, camera, or contacts.
Google Play Protect: This scans apps for malware and warns users of potential risks.
Regular Security Patches: Google releases monthly security updates to patch vulnerabilities.
Advantages:
Wide Adoption: Android dominates the global smartphone market, making it an attractive platform for developers.
Flexibility: Its open-source nature allows manufacturers and developers to innovate and differentiate their products.
Large Developer Community: A massive community provides support, tutorials, and open-source libraries.
Cost-Effective: Most Android devices are available at various price points, making the platform accessible.
Challenges:
Fragmentation: Due to the diversity of devices and manufacturers, Android faces fragmentation, leading to inconsistencies in app performance.
Security Risks: Open-source flexibility sometimes exposes devices to malware or unauthorized modifications.
Complex Testing: The wide variety of screen sizes, resolutions, and hardware specifications requires thorough testing.
Android continues to evolve, with Google focusing on improving user experience, privacy, and integration across devices. Technologies like AI, machine learning, augmented reality, and 5G are becoming more integrated into Android apps. With Android’s continuous updates and support for innovative hardware, it is poised to maintain its leadership in mobile computing for years to come.
Answer:
Android is an open-source, Linux-based operating system developed by Google, primarily used for mobile devices like smartphones and tablets. It provides a rich application framework for developers to create innovative apps and runs on the Dalvik/ART virtual machine.
Answer:
Open-source: Android is freely available to developers.
Linux Kernel-based: Offers security and memory management.
Rich UI: Supports XML-based layouts and multiple UI components.
Multitasking: Allows running multiple apps simultaneously.
Connectivity: Supports Bluetooth, Wi-Fi, NFC, and more.
App Development: Provides Java/Kotlin SDK for app creation.
Answer:
Android has a four-layer architecture:
Linux Kernel: Low-level hardware interface, security, memory management, and drivers.
Libraries & Android Runtime:
Libraries: SQLite, WebKit, OpenGL, Media framework.
Android Runtime: Includes Dalvik/ART VM and core Java libraries.
Application Framework: APIs for building apps (Activity Manager, Resource Manager, Content Providers).
Applications: User-installed apps (Gmail, WhatsApp) and system apps.
Answer:
An Activity represents a single screen in an app.
It interacts with users and controls UI components like buttons, text fields, etc.
Lifecycle methods: onCreate(), onStart(), onResume(), onPause(), onStop(), onDestroy().
| Activity | Fragment |
|---|---|
| Represents a full-screen UI. | Represents a portion of UI. |
| Cannot exist without an Activity. | Must exist inside an Activity. |
| Has its own lifecycle. | Has its own lifecycle but depends on the parent Activity. |
Answer:
An Intent is a messaging object to request actions from other app components.
Types:
Explicit Intent: Targets a specific component (Activity/Service).
Implicit Intent: Declares general action to be handled by any suitable app.
Example: Open a URL using an Intent.
Answer:
A Service is a component that performs background operations without a user interface.
Types:
Started Service: Runs until stopped (startService()).
Bound Service: Runs as long as another app binds to it (bindService()).
Answer:
A component that responds to system-wide broadcast messages, like battery low or Wi-Fi connectivity changes.
Registered in AndroidManifest.xml or dynamically via code.
Example: Listen for incoming SMS or network changes.
Answer:
Content Providers allow apps to share data between them in a secure manner.
Uses URI (Uniform Resource Identifier) to access data.
Example: Accessing contacts, media files, or calendar events.
Answer:
A configuration file that defines app components: Activities, Services, Broadcast Receivers, permissions, and app metadata.
Essential for app execution as Android uses it to know components and required permissions.
Answer:
Internal Storage: Private to the app, secure.
External Storage: Shared, less secure, requires permission.
SharedPreferences: Stores key-value pairs (like settings).
SQLite Database: Local structured database.
Room Database: Modern SQLite wrapper for structured data storage.
| Serializable | Parcelable |
|---|---|
| Standard Java interface. | Android-specific interface. |
| Slower, uses reflection. | Faster, manual implementation. |
| Easy to implement. | Requires more code. |
| Can be used outside Android. | Only for Android inter-component communication. |
Answer:
onCreate(): Initialize components.
onStart(): Activity becomes visible.
onResume(): Activity starts interacting with the user.
onPause(): Activity partially hidden, save data.
onStop(): Activity no longer visible.
onDestroy(): Cleanup before destruction.
onRestart(): Activity restarting after being stopped.
Threads: Perform long-running tasks to avoid blocking UI.
AsyncTask (Deprecated): Simplified way to run tasks in background and update UI.
Methods: doInBackground(), onPreExecute(), onPostExecute(), onProgressUpdate().
| Service | Thread |
|---|---|
| Runs in background and can run indefinitely. | Runs in background but bound to the app’s process. |
| Does not run on UI thread by default. | Must manage UI updates with Handler/Looper. |
| Used for long-running operations like downloading. | Used for small background tasks. |
Answer:
Gradle is a build automation tool used in Android Studio. It handles dependencies, builds, and packaging.
Build Types: debug, release.
Dependency Management: External libraries are added in build.gradle.
Answer:
Activities – Screens
Fragments – Reusable UI parts
Services – Background tasks
Broadcast Receivers – Event handling
Content Providers – Data sharing
Intents – Communication between components
onSaveInstanceState() and onRestoreInstanceState()?onSaveInstanceState(): Called before an Activity may be destroyed to save UI state.
onRestoreInstanceState(): Called after onStart() to restore the saved state.
Answer:
PendingIntent allows an app to pass a future intent to another app or system service.
Commonly used with Notifications, AlarmManager, or Widgets.
Answer:
A set of libraries, tools, and guidelines to make Android app development faster and easier.
Includes:
Architecture Components: LiveData, ViewModel, Room, WorkManager.
UI Components: Navigation, Paging, MotionLayout.
Behavior Components: Notifications, Permissions.
Answer:
Avoid long-lived references to Context.
Use WeakReference for large objects.
Unregister listeners in onDestroy() or onStop().
Use LeakCanary tool for detection.
dp, sp, and px| Unit | Purpose |
|---|---|
px |
Pixels, absolute screen size. |
dp |
Density-independent pixels, adjusts to screen density. |
sp |
Scaled pixels, used for fonts, respects user’s font size settings. |
Answer:
Application Not Responding (ANR) occurs when an app blocks the main thread for too long (usually >5 seconds).
Avoid by using background threads for heavy tasks.
Answer:
Use RecyclerView instead of ListView.
Avoid memory leaks.
Minimize layout hierarchies.
Use Glide/Picasso for image loading.
Lazy loading and caching of data.
Service, IntentService, and JobIntentService| Service | IntentService | JobIntentService |
|---|---|---|
| Runs on main thread. | Runs on a background thread. | Runs on background thread, supports API 26+ restrictions. |
| Needs manual thread management. | Stops automatically when work is done. | Handles background work efficiently with system constraints. |
Answer:
Kotlin is a modern programming language officially supported by Google for Android development.
| Java | Kotlin |
|---|---|
| Verbose code | Less boilerplate |
| NullPointerException common | Null safety built-in |
| Slower development | Faster development |
| No extension functions | Supports extension functions |
| More lines of code | Concise syntax |
Answer:
Context is a reference to the current state of the application. It allows access to resources, databases, preferences, and system services.
Types of Context:
Application Context – Lifetime of the app
Activity Context – Lifetime of an activity
| Application Context | Activity Context |
|---|---|
| Lives throughout app lifecycle | Lives until activity is destroyed |
| Used for global tasks | Used for UI-related tasks |
| Cannot inflate UI | Can inflate UI |
Answer:
RecyclerView is an advanced version of ListView used to display large datasets efficiently.
Key components:
Adapter
ViewHolder
LayoutManager
Advantages:
Better performance
View recycling
Supports animations and different layouts
| ListView | RecyclerView |
|---|---|
| Less flexible | Highly flexible |
| No ViewHolder pattern by default | Mandatory ViewHolder |
| Slower | Faster |
| Limited animations | Built-in animations |
Answer:
ViewModel is part of Android Jetpack Architecture Components.
It stores and manages UI-related data in a lifecycle-conscious way.
Benefits:
Survives configuration changes
Prevents data loss on screen rotation
Separates UI logic from business logic
Answer:
LiveData is an observable data holder that is lifecycle-aware.
Advantages:
Automatically updates UI
Prevents memory leaks
Works well with ViewModel
Answer:
MVVM stands for:
Model – Data layer
View – UI (Activity/Fragment)
ViewModel – Business logic
Advantages:
Clean code
Easy testing
Better separation of concerns
Answer:
Data Binding allows binding UI components directly to data sources.
Benefits:
Reduces boilerplate code
Eliminates findViewById()
Better code readability
| findViewById | ViewBinding |
|---|---|
| Runtime errors possible | Compile-time safety |
| More boilerplate | Less code |
| Slower | Faster |
Answer:
Room is an ORM (Object Relational Mapping) library built on SQLite.
Components:
Entity
DAO
Database
Advantages:
Compile-time query validation
Easy database access
Works with LiveData
Answer:
REST API allows Android apps to communicate with servers using HTTP methods:
GET
POST
PUT
DELETE
Answer:
Retrofit is a type-safe HTTP client for Android.
Advantages:
Easy API calls
Supports JSON parsing
Integrates with Gson and Moshi
| Retrofit | Volley |
|---|---|
| Used for REST APIs | Used for small network calls |
| Better for large data | Faster for small data |
| Supports RxJava | No RxJava support |
Answer:
JSON (JavaScript Object Notation) is a lightweight data-interchange format used in APIs.
Answer:
Permissions allow apps to access restricted system features.
Types:
Normal permissions
Dangerous permissions (Camera, Location)
Answer:
From Android 6.0 (API 23), dangerous permissions must be requested at runtime.
| Toast | Snackbar |
|---|---|
| Small popup message | Interactive message |
| No user action | Supports actions |
| Limited customization | More customizable |
Answer:
Dialog is a small window that prompts users to make a decision or enter information.
Answer:
ConstraintLayout is a flexible layout that allows positioning UI elements relative to others.
Advantages:
Flat view hierarchy
Better performance
Responsive design
Answer:
APK (Android Package Kit) is the file format used to distribute Android apps.
| APK | AAB |
|---|---|
| Direct install | Google Play optimized |
| Larger size | Smaller downloads |
| Manual updates | Dynamic delivery |
Answer:
ProGuard shrinks, optimizes, and obfuscates code to protect it.
Answer:
Firebase is a backend platform by Google.
Services:
Authentication
Firestore
Realtime Database
Cloud Messaging
Crashlytics
Answer:
Push notifications are messages sent from servers to devices using Firebase Cloud Messaging (FCM).
Answer:
WorkManager handles background tasks reliably, even after app restarts.
| AsyncTask | WorkManager |
|---|---|
| Deprecated | Recommended |
| Short tasks | Long, deferrable tasks |
| Not lifecycle aware | Lifecycle aware |
Answer:
Stores small key-value data like login status or settings.
Answer:
Simplifies navigation between fragments and activities.
Answer:
Allows users to open a specific screen using a URL.
Answer:
Emulator simulates an Android device on a computer for testing.
| Emulator | Real Device |
|---|---|
| Slower | Faster |
| No hardware limitations | Real-world testing |
| Limited sensors | Actual sensors |
Answer:
Debugging is the process of finding and fixing errors using Logcat and breakpoints.
Answer:
Logcat displays system logs and app logs.
Answer:
SDK (Software Development Kit) provides tools, APIs, and libraries for Android app development.
Answer:
In real projects, MVVM with Clean Architecture is commonly used.
Layers:
Presentation – Activity/Fragment + ViewModel
Domain – Business logic, UseCases
Data – Repository, Remote & Local data sources
Benefits:
Separation of concerns
Easy testing
Lifecycle awareness
Scalability
| MVVM | MVP |
|---|---|
| ViewModel survives config changes | Presenter does not |
| LiveData observes UI | Manual callbacks |
| Less boilerplate | More boilerplate |
| Recommended by Google | Older approach |
Answer:
ViewModel is stored in the ViewModelStore, which survives configuration changes like screen rotation.
When Activity is recreated, the same ViewModel instance is reused.
Answer:
Use ViewModel
Store UI state using SavedStateHandle
Avoid keeping references to Context
Use onSaveInstanceState() for temporary UI data
Answer:
ANR occurs when the main thread is blocked for more than 5 seconds.
Avoid ANR by:
Moving heavy tasks to background threads
Using WorkManager or Coroutines
Optimizing database queries
Avoiding long operations in lifecycle methods
Answer:
Coroutines simplify async programming.
Key elements:
suspend functions
Dispatchers.Main, IO, Default
CoroutineScope
Advantages:
Cleaner code
Structured concurrency
Lifecycle aware using viewModelScope
| Coroutines | RxJava |
|---|---|
| Simpler | Steeper learning curve |
| Lightweight | Heavy |
| Built-in Kotlin support | External dependency |
| Recommended now | Still used in legacy apps |
Answer:
WorkManager is used for deferrable background tasks that must run even if the app is killed.
Use cases:
Upload logs
Sync data
Periodic background tasks
| WorkManager | JobScheduler | AlarmManager |
|---|---|---|
| Guaranteed execution | System-managed | Time-based |
| Backward compatible | API 21+ | Less reliable |
| Recommended | Advanced use | Rarely used |
Answer:
Use ListAdapter with DiffUtil
Enable view recycling
Use stable IDs
Avoid deep layout nesting
Use paging for large datasets
Answer:
DiffUtil calculates differences between old and new lists and updates only changed items, improving RecyclerView performance.
Answer:
Paging 3 loads data in chunks.
Benefits:
Reduced memory usage
Handles large datasets
Integrates with Room & Retrofit
Answer:
Use Retrofit
Handle responses using sealed classes
Use Coroutines
Implement retry & error handling
Cache using Room
Answer:
Interceptors in OkHttp
Common error wrapper
Centralized error handling in Repository
Show meaningful UI states
Answer:
Repository acts as a single source of truth, managing data from network and database.
Answer:
EncryptedSharedPreferences
Keystore system
Avoid hardcoding secrets
Enable ProGuard/R8
Use HTTPS with SSL pinning
Answer:
SSL pinning restricts app communication to trusted certificates, preventing MITM attacks.
Answer:
Avoid static references to Context
Use WeakReference
Clear bindings in onDestroyView()
Use LeakCanary
| onCreate() | onStart() |
|---|---|
| Initialize UI | Activity becomes visible |
| Called once | Can be called multiple times |
Answer:
It saves UI-related data that survives process death.
Answer:
Use Foreground Service
Request background location permission
Follow Android 10+ restrictions
Answer:
Compose is a declarative UI toolkit replacing XML.
Advantages:
Less boilerplate
Reactive UI
Faster UI development
| XML | Compose |
|---|---|
| Imperative | Declarative |
| More boilerplate | Less code |
| Slower UI updates | Reactive UI |
Answer:
Configure intent filters
Use Navigation Component
Handle parameters safely
Answer:
Separate features into modules
Faster build times
Better code isolation
Answer:
DI provides dependencies from outside rather than creating them internally.
| Dagger | Hilt |
|---|---|
| Boilerplate heavy | Simplified |
| Manual setup | Auto-generated |
| Complex | Easy |
Answer:
Unit tests (JUnit, Mockito)
UI tests (Espresso)
Integration tests
Answer:
Cache data using Room
Sync when network available
Show cached data
Answer:
Code shrinking
Obfuscation
Optimization
Answer:
Use productFlavors
Separate environments (dev, staging, prod)
Answer:
Android App Bundle reduces app size and optimizes delivery.
Answer:
Lazy initialization
Remove heavy logic from onCreate()
Use App Startup library
Answer:
StrictMode detects accidental disk/network access on main thread.
Answer:
Handling performance issues, memory leaks, and background execution restrictions while maintaining smooth UX.
Answer:
Process death happens when the system kills the app to reclaim memory.
Handling strategies:
Use SavedStateHandle in ViewModel
Persist critical data in Room
Avoid relying only on ViewModel
Restore state in onCreate()
| Configuration Change | Process Death |
|---|---|
| Activity recreated | App process killed |
| ViewModel survives | ViewModel destroyed |
| Predictable | Unpredictable |
Answer:
A foreground service performs user-visible tasks with a persistent notification.
Use cases:
Location tracking
Music playback
File upload/download
Answer:
Background services restricted
Use WorkManager
Use Foreground Services
JobScheduler for deferred work
Answer:
Use Logcat
Analyze ANR traces
Use StrictMode
Avoid blocking main thread
Answer:
Use Glide or Coil
Resize images
Avoid loading full-size bitmaps
Use caching
Answer:
Bitmap pooling reuses bitmap memory to reduce GC overhead and improve performance.
Answer:
Use AAB
Enable R8
Remove unused resources
Use WebP images
Answer:
Main thread for UI
Background threads for heavy work
Use Coroutines / Executors
Answer:
Looper manages message queue
Handler posts tasks to Looper
Answer:
WorkManager with PeriodicWorkRequest
Avoid AlarmManager unless necessary
Answer:
Optimizes app startup by initializing components lazily.
| Deep Linking | App Linking |
|---|---|
| Works with any app | Verified domain |
| Can be intercepted | Secure |
Answer:
Remote Config (Firebase)
Build variants
Server-side flags
Answer:
Use ConnectivityManager
Observe network state
Handle offline scenarios gracefully
Answer:
Track page number
Load on scroll
Handle loading states
Cache data
Answer:
Clean Architecture separates concerns into independent layers with clear dependency rules.
Answer:
One authoritative data source ensures consistency and reliability.
Answer:
try-catch
CoroutineExceptionHandler
Structured concurrency
| launch | async |
|---|---|
| Fire-and-forget | Returns result |
| No return value | Returns Deferred |
Answer:
Flow is a cold asynchronous data stream.
| Flow | LiveData |
|---|---|
| Kotlin native | Android-specific |
| Supports operators | Limited |
| Cold stream | Hot stream |
Answer:
Use repeatOnLifecycle
Avoid memory leaks
Cancel automatically
Answer:
StateFlow holds UI state
SharedFlow emits events
Answer:
SharedFlow
Event wrapper
Channel
Answer:
Firebase Crashlytics
Log meaningful exceptions
Monitor crash trends
Answer:
Do not hardcode
Use backend token exchange
Use Keystore
Answer:
Sharing data
App widgets
Inter-app communication
Answer:
Backward compatibility
Database migrations
Feature flags
Answer:
Handles schema changes without data loss.
Answer:
LeakCanary
Android Profiler
Heap dump analysis
Answer:
Use FCM
Handle background & foreground
Manage notification channels
Answer:
Limits file access to improve security (Android 10+).
Answer:
DownloadManager
Foreground service for large files
Answer:
Follow permission guidelines
Use privacy policy
Data safety declaration