Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A foreground service cannot guarantee that Android will keep its process alive. To recover after process death, choose the right onStartCommand() restart mode, save enough task state to rebuild the work, and follow the foreground-service launch and type requirements for the device and your app’s target SDK.

What happens when Android kills a foreground service?

A foreground service makes its process more important to the system because the work is visible to the user. It is not immortal: Android can still kill the process when memory pressure requires it. Whether Android later recreates a started service, and whether it supplies the last start command again, depends on the value returned from onStartCommand(). See Android’s process and app lifecycle documentation.

Process death also destroys ordinary in-memory state. A recreated service must recover from durable app state rather than assuming its previous objects, fields, or progress remain available.

Choose a restart mode that matches the work

Restart mode What Android does after process death When it fits
START_STICKY Android may recreate the service in its started state, but does not retain the last Intent. If no new start command is pending, onStartCommand() receives a null Intent. Ongoing work whose task and parameters can be reconstructed from saved state, such as media playback.
START_REDELIVER_INTENT Android schedules a restart and redelivers the last delivered Intent. A job for which replaying the last command is the appropriate trigger, such as a download. Save progress separately and make replay safe.
START_NOT_STICKY Android does not recreate the service solely because it was started if no new start Intent is pending. Work that may be abandoned under memory pressure and can be started again later.

These are restart behaviors, not guarantees that work will complete. The Service API reference documents the contracts; Android’s services overview describes the modes and their use cases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build recovery into the service

  1. Persist the task before relying on it. Save the task identity, parameters, and progress needed to resume. Treat the Intent as a command or input, not your only durable record of the job.
  2. Start from a permitted context. Use context.startForegroundService(intent) when the foreground-service flow is allowed for your app and situation.
  3. Promote the service promptly. In the service, create and post a user-visible notification by calling ServiceCompat.startForeground(...). Calling startForegroundService() on the caller does not itself make the service foreground.
  4. Validate each start command. In onStartCommand(), check the incoming Intent and its parameters. If using START_STICKY, handle a null Intent by loading the current task from durable state or determining that there is no work to resume.
  5. Make resumption safe. A command may be replayed, and a process may have stopped partway through an operation. Use durable progress and idempotent handling so a resumed task does not produce harmful duplicate effects.
  6. Return the matching mode. Use START_STICKY for ongoing work reconstructed from saved state, START_REDELIVER_INTENT when redelivery is the right recovery trigger, or START_NOT_STICKY when automatic recreation is unwanted.
  7. Stop when the task ends. Stop the service after the user-visible task finishes or is cancelled; recovery should not resurrect work the user has ended.

Android’s API documentation specifically notes that, starting with Android 12, a sticky foreground-service restart is not blocked by the background-start restriction. That exception applies to a system-managed sticky restart—not to a fresh background start initiated by the app.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Meet the launch rules for your Android version

  • Targeting Android 12 (API 31) or later: apps generally cannot start a foreground service while in the background unless a documented exemption applies. A disallowed launch can throw ForegroundServiceStartNotAllowedException. See restrictions on starting a foreground service from the background.
  • Targeting Android 14 (API 34) or later: satisfy the permission and prerequisite requirements for the declared foreground-service type. For example, a location service needs the applicable location permission. Missing type-related permissions or prerequisites can cause a SecurityException. Review Android’s foreground-service launch guidance and troubleshooting documentation.
  • Targeting Android 9 (API 28) or later: Android’s troubleshooting guidance says the general FOREGROUND_SERVICE permission is required to launch a foreground service.
  • For every target: declare an appropriate foreground-service type. The type passed when promoting the service must be a subset of the types declared for that service in the manifest. Promotion also has timing requirements; check the troubleshooting guidance if it fails.

Requirements vary with device OS, target SDK, and service type, so verify the current rules for the combination you support.

Diagnose common restart failures

  • The service restarts without its original command: this is expected with START_STICKY. Handle a null Intent and reconstruct work from persisted state, or choose redelivery if replaying the last command is the desired behavior.
  • The process still dies: foreground status improves process importance but does not prevent process death under memory pressure. Implement recovery instead of depending on continuous process survival.
  • A background launch fails: for apps targeting API 31 or later, check whether the launch is fresh and app-initiated, and whether a documented exemption applies. Do not confuse that case with Android restarting a sticky service.
  • Promotion throws a security error or fails: check the declared service type, the type passed to startForeground, required permissions and prerequisites, and the launch timing requirements for the target SDK.
  • Work repeats incorrectly or loses progress: move essential task state out of process memory and make commands safe to resume or replay.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.