Services & Background Work Interview Questions
ANDROID › Components
What are the types of Service on Android, and how do started and bound services differ?
What a strong answer covers: A started service runs after startService or startForegroundService until it stops itself; a bound service runs while clients are bound through bindService and talk to it through an IBinder interface. A foreground service shows a persistent notification and is less likely to be killed. A service runs on the main thread by default, so heavy work must go to a background thread.
When should you use WorkManager instead of a Service?
What a strong answer covers: WorkManager is for deferrable work that must be guaranteed to run even if the app exits or the device restarts, like syncing, uploading logs or backing up. It respects constraints (network, charging) and battery optimisations. A foreground service is for work the user is aware of right now that must continue, like music playback, navigation or an active call. Coroutines alone are for work tied to the app being open.
What restrictions has Android added to background work and foreground services over recent versions?
What a strong answer covers: Android 8 limited background services and implicit broadcasts. Android 12 forbids starting foreground services from the background in most cases. Android 13 requires the POST_NOTIFICATIONS permission for the notification to show. Android 14 requires a foreground service type declared in the manifest, with matching permissions (dataSync, location, mediaPlayback and so on), and Google Play policy reviews them.
How does WorkManager guarantee work runs, and how would you chain work or make it unique?
What a strong answer covers: It persists work requests in its own database and schedules them through JobScheduler, so work survives process death and reboots. You chain with beginWith(a).then(b).enqueue(), passing data between workers. enqueueUniqueWork with a name and an ExistingWorkPolicy (KEEP, REPLACE, APPEND) prevents duplicates. Use CoroutineWorker for suspend code, with retry via Result.retry and a backoff policy. Expedited work is for short urgent tasks.
Design background upload of photos that must survive app close, poor networks and reboots, and show progress. Which components would you use and why?
What a strong answer covers: Store pending uploads in Room. Enqueue unique WorkManager work per photo or batch with a network constraint and exponential backoff. Use a CoroutineWorker that uploads in chunks (resumable if the server supports it), calls setProgress for in-app progress observed through getWorkInfoByIdFlow, and setForeground for a notification on long uploads. Use idempotency keys so retries don't duplicate. Update Room on completion so the UI reflects the result.