Context, Application & Manifest Interview Questions
ANDROID › System
What is a Context, and what's the difference between Application context and Activity context?
What a strong answer covers: Context is the handle to app resources, system services, and starting components. Application context lives as long as the process and is safe to keep in singletons. Activity context is tied to the activity, carries its theme and configuration, and is needed for UI work like inflating themed views, showing dialogs and starting activities without NEW_TASK. Holding an Activity context in a long-lived object leaks the activity.
What goes in AndroidManifest.xml?
What a strong answer covers: The package's components (activities, services, receivers, providers) with intent filters and exported flags, permissions requested and defined, the Application class, hardware and software features required, queries for package visibility, metadata for libraries, and attributes like theme, icon, backup and network security config. Manifests from libraries and build variants are merged into one.
What is the Application class used for, and what shouldn't you put in it?
What a strong answer covers: It's created before any other component and lives for the process. It's for app-wide setup like dependency injection (Hilt's @HiltAndroidApp), crash reporting and logging. Don't do heavy work in onCreate because it delays every cold start, including starts triggered by a background broadcast; don't use it as a global place for mutable state that won't survive process death.
How does manifest merging work, and how do you resolve conflicts from libraries?
What a strong answer covers: The build merges your app manifest with every library's manifest and build variant manifests, with higher-priority manifests winning. Conflicts like two different values for an attribute fail the build. You resolve them with tools:replace, tools:remove or tools:node='remove' (for example, to remove a permission a library adds), and check the merged result in Android Studio's Merged Manifest view.
What are the signs that someone used the wrong Context, and what bugs result?
What a strong answer covers: Using Application context to inflate views loses the activity's theme, so styles and dark mode are wrong; showing a dialog with Application context crashes with BadTokenException; starting an activity from Application context needs FLAG_ACTIVITY_NEW_TASK and creates a separate task; holding an Activity in a singleton, static field or long-lived callback leaks it (LeakCanary finds this). Also, a configuration-specific context is needed for per-locale or per-display resources.