Android Interview Questions
What is Android?
Android is an open-source, Linux-based operating system used for mobile devices like smartphones and tablets. It is developed by Google and supports Java, Kotlin, and C++ for app development.
What are the components of Android architecture?
- Linux Kernel
- Libraries
- Android Runtime
- Application Framework
- Applications
What is an Activity in Android?
An Activity is a single screen with a user interface, like a window or page in a desktop application. It's the entry point for interacting with the user.
What is the difference between onCreate(), onStart(), and onResume()?
- onCreate(): Called when the activity is first created.
- onStart(): Called when the activity becomes visible to the user.
- onResume(): Called when the activity starts interacting with the user.
What is a Fragment?
A Fragment is a reusable portion of the UI in an Activity. It has its own lifecycle and can be combined to create multi-pane UIs.
What is the AndroidManifest.xml file?
It provides essential information about your app to the Android system, such as package name, components, permissions, etc.
What is the use of intent in Android?
Intents are used to start activities, services, or send broadcasts. They enable communication between components.
What are implicit and explicit intents?
- Explicit: Starts a specific component.
- Implicit: Asks the system to find a suitable component.
What is the Application class in Android?
It's the base class of the app where global application state can be maintained.
What is the difference between Service and IntentService?
- Service runs on the main thread.
- IntentService runs on a background thread and stops itself after work is done.
What is a BroadcastReceiver?
It listens for system-wide broadcast announcements (like battery low, airplane mode, etc.).
What is a Content Provider?
It manages access to a structured set of data and shares data between different apps.
What is ViewModel in Android?
A lifecycle-aware component used to store and manage UI-related data for an Activity or Fragment.
What is LiveData?
An observable data holder class that is lifecycle-aware. UI components observe LiveData to get updated data.
What is Room in Android?
It is a persistence library that provides an abstraction layer over SQLite to allow fluent database access.
What is Jetpack?
A set of Android libraries (like Navigation, Lifecycle, ViewModel, Room) that helps developers follow best practices and write robust code.
What is an ANR?
Application Not Responding – occurs when the UI thread is blocked for too long (more than 5 seconds).
How to avoid memory leaks in Android?
- Use WeakReferences
- Avoid static references to Activities
- Unregister listeners
- Use lifecycle-aware components
What is the use of Proguard in Android?
Proguard shrinks, optimizes, and obfuscates your code to make it hard to reverse-engineer.
What is the difference between dp, sp, and px?
- dp (density-independent pixels): Scales with screen density
- sp (scale-independent pixels): Like dp but also scaled by user’s font preference
- px (pixels): Exact number of screen pixels
What is Data Binding in Android?
It binds UI components in XML layouts to data sources in your app using a declarative format.
How does Garbage Collection work in Android?
Dalvik/ART uses a mark-and-sweep algorithm to reclaim memory by destroying unreachable objects.
What is the difference between Serializable and Parcelable?
- Serializable: Java-based, slower, more convenient
- Parcelable: Android-specific, faster, recommended for performance
What is Dependency Injection?
A design pattern used to inject objects into classes rather than creating them inside. Dagger/Hilt are popular DI libraries.
What are Coroutines in Android?
Coroutines are used for asynchronous programming in Kotlin. They help run long-running tasks without blocking the main thread.