How do I start my app when the phone starts on Android?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Android can notify your app when the device finishes booting, but that does not mean you should immediately launch a screen. The correct pattern is usually to receive the boot broadcast, do lightweight initialization, and schedule background work or a service only when the app’s purpose truly requires it.
How Boot Startup Works
After the system finishes booting, Android sends the BOOT_COMPLETED broadcast. Apps that declare the RECEIVE_BOOT_COMPLETED permission and a matching BroadcastReceiver can react to it.
At a minimum, you need two things:
- the permission in the manifest
- a receiver that listens for the boot action
Here is a basic manifest setup.
Implement the Receiver
The receiver should stay small. Boot is a sensitive phase of device startup, and heavy work here can hurt performance.
Using WorkManager is a good default because it lets Android schedule the follow-up work appropriately instead of forcing the receiver to do everything immediately.
Do Not Launch an Activity Unless You Truly Mean To
A lot of older answers suggest starting your main activity directly from the boot receiver. That is usually a poor user experience and, on modern Android, may not behave the way you expect because of background-start restrictions.
If the goal is to resume syncing, monitoring, scheduled jobs, or notification setup, start background work instead. Only launch a visible activity automatically when the product genuinely requires kiosk-like behavior and you have designed for platform restrictions and user expectations.
Example Worker
The boot receiver above schedules a worker. The worker can refresh alarms, restore a periodic job schedule, or reinitialize app state.
This separation keeps the receiver fast and makes the post-boot workflow easier to test.
Version and Device Considerations
Boot behavior has become stricter over time. Background execution limits, battery optimizations, and manufacturer customizations can all affect what happens after boot.
A few practical rules help:
- assume the receiver will not be the right place for long-running work
- test on the Android versions and device vendors you actually support
- expect users to care if your app starts doing work at boot without a clear reason
Some apps also need to handle LOCKED_BOOT_COMPLETED if they must run before the user unlocks the device. That is a more specialized case and requires direct-boot-aware design.
Common Pitfalls
Starting a full UI from the receiver is the most common architectural mistake. It is usually better to schedule background work and let the user open the app normally.
Forgetting the RECEIVE_BOOT_COMPLETED permission will prevent the receiver from being called.
Doing expensive work directly inside onReceive() is another problem because the receiver is expected to finish quickly.
Finally, do not assume all device vendors treat boot-time behavior identically. Test on real hardware, not only an emulator.
Summary
- listen for
BOOT_COMPLETEDwith a manifest-declaredBroadcastReceiver - include the
RECEIVE_BOOT_COMPLETEDpermission - keep the receiver lightweight and hand off real work to
WorkManageror another appropriate mechanism - avoid launching an activity at boot unless the product explicitly requires that behavior
- test boot-time flows on the Android versions and devices you support
Related reading
- How do I switch UISegmentedControl programmatically?
- How do I take a full screen Screenshot in Swift?
- How do I take a full screen Screenshot in Swift?
- How Do I Take a Screen Shot of a UIView?
- How do I test if a string is empty in Objective-C?
- How do I upload a build to iTunes Connect for TestFlight?
- How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView
- How do I use a UISegmentedControl to switch views?
.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.