When would you choose Foreground Service over WorkManager?

Tests immediate user-visible work versus deferrable jobs. Strong answers cite a notification-driven use case the user actively expects, like live navigation or a workout. Red flag: claiming WorkManager replaces real-time foreground tasks.
What's really being asked
This question checks if you understand the boundary between immediate user-visible work and deferrable background work on Android. The interviewer wants to see that you know Foreground Services are bound to a persistent notification and are meant for tasks the user actively expects to continue, while WorkManager is the API for guaranteed but deferrable background tasks that do not need to run instantly and can wait for optimal conditions.
The full answer
First, state the core distinction: a Foreground Service runs immediately and must display a persistent notification, whereas WorkManager schedules work that can be deferred and constrained by network or battery conditions. Second, give a specific user-facing use case where the task must start right away and remain ongoing while the user is aware of it, such as a live fitness workout tracking location and heart rate, turn-by-turn navigation providing audio cues, or a music player streaming content. Third, mention that starting a foreground service from the background carries restrictions and requires declaring the service in the manifest and requesting the correct permissions. Fourth, explain why WorkManager is wrong for this scenario because it does not promise immediate execution and could delay the task until constraints are met, breaking real-time user expectations and degrading the experience.
The mistakes people make
Saying you would use a Foreground Service for periodic data sync or upload jobs that do not need a notification. Claiming WorkManager can handle time-critical or user-interactive tasks. Failing to mention the persistent notification requirement. Ignoring system restrictions on starting foreground services from the background. Suggesting a plain background Service without the foreground designation or dismissing the notification as optional.
What usually comes next
How do you handle the new restrictions on starting foreground services from the background in recent Android versions? What foreground service type would you declare for your specific use case? How do you manage the service lifecycle if the user swipes the app away or the system imposes a service timeout? When would you combine WorkManager with a foreground service, or use expedited WorkManager instead?
A concrete example
A fitness app recording an outdoor run should use a Foreground Service. The user starts the workout, expects GPS and heart rate sampling to begin immediately, and needs a persistent notification showing elapsed time and distance. WorkManager cannot guarantee the workout starts the moment the user presses begin, and the user must be able to pause or stop the run from the notification. The service must be declared in the manifest and request the appropriate foreground service type for location, and the app must respect background start restrictions by launching it while the app is in the foreground or by using an approved exemption.
Interview question
Which ongoing user-facing task requires a Foreground Service instead of WorkManager?
- a.Checking for new emails every 30 minutes in the background
- b.Tracking a live workout with GPS and a persistent notificationCorrect
- c.Uploading a large file immediately after the user presses send
- d.Running a daily backup when the device is idle and charging
Why? this is the answer
The card states that Foreground Services are for tasks the user actively expects to continue, such as a live workout, and must show a persistent notification. Option C is tempting because a user-initiated upload feels urgent, but the card explicitly lists upload jobs that do not need a notification as a common wrong answer for Foreground Service.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
- #android
- #foreground-service
- #workmanager
- #background-work
- #services
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles