Register Application class in Manifest?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In Android, a custom Application class gives you one place to initialize app-wide state before any activity starts. It only runs if Android knows about it, which is why you must register it in the manifest.
What the Application Class Is For
Application is the process-level entry point for your app. Android creates it before launching your first activity, service, or receiver in that process. That makes it a reasonable place for work that truly belongs to the whole app, such as:
- setting up logging
- initializing dependency injection
- configuring analytics
- creating singletons that live for the process
It is not the right place for screen-specific state, network calls that can wait, or anything that makes startup noticeably slower.
Here is a minimal custom implementation in Kotlin:
This class exists, but Android will not instantiate it until you declare it in AndroidManifest.xml.
How to Register It in the Manifest
The registration happens on the application element through the android:name attribute.
If the class is in the same package as the app, .MyApp is enough. If it lives elsewhere, use the full package name.
Once that attribute is present, Android creates MyApp during process startup and calls onCreate.
When You Actually Need a Custom Application
Many apps do not need one at all. If you only wanted a shared helper object, a dependency injection container or a lazily created singleton may be cleaner. Use a custom Application class when the work is truly app-wide and should happen once per process.
Common examples include setting up Hilt, WorkManager configuration, or a crash reporter.
In that case, the manifest still needs the class name, unless your build setup injects it through a generated manifest merge. In normal app code, checking the merged manifest is the safest way to confirm what will ship.
How to Verify It Is Working
The simplest test is to log from onCreate and launch the app. You can also inspect the merged manifest in Android Studio to confirm that the android:name value is present after manifest merging from libraries and build variants.
If you are debugging startup issues, keep onCreate short. A lightweight sanity check is fine:
That kind of validation is acceptable. Heavy I/O or long synchronous setup is not.
Common Pitfalls
- Creating the class but forgetting to register it. The app still runs, but your custom startup code never executes.
- Using the wrong package name in
android:name. This usually shows up as a startup crash because Android cannot instantiate the class. - Putting too much work in
onCreate. Slow initialization hurts cold start time. - Treating
Applicationas a global dump for mutable state. That makes testing and lifecycle management harder. - Forgetting about manifest merging. A library or product flavor can change the final manifest, so inspect the merged result when behavior is unexpected.
Summary
- A custom
Applicationclass is optional and should be used only for real app-wide startup work. - Register it in
AndroidManifest.xmlwith theandroid:nameattribute on theapplicationelement. - Use a relative class name such as
.MyApponly when it is in the app package. - Keep
onCreatesmall and avoid heavy blocking work during process startup. - If registration seems correct but the class is not used, inspect the merged manifest for the final value.
Related reading
- Registering for Push Notifications in Xcode 8/Swift 3.0?
- Reload activity in Android
- reloadData of UITableView with Dynamic cell heights causes jumpy scrolling
- reloadData of UITableView with Dynamic cell heights causes jumpy scrolling
- Remove all constraints affecting a UIView
- Remove all non-numeric characters from a string in swift
- Remove all unused resources from an android project
- Remove background drawable programmatically in Android
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.