How to keep Android app running after it is removed from the recent tasks list?


I am developing an Android application using Kotlin. I want my app to continue running even after the user removes it from the recent tasks list (swipes the app away).

Currently, when the user removes the app from the recent apps screen, the process stops and the service also stops. I would like the application (or a background service) to keep running.

I tried using a Foreground Service and START_STICKY, but the service still stops when the app is removed from the recent task list.

My questions:

  1. Is it possible to keep the app running after it is removed from the recent tasks list?

  2. What is the recommended approach in Android for this situation?

  3. Should I handle this using onTaskRemoved() or another mechanism?

The app is written in Kotlin and targeting modern Android versions.

Any guidance or example code would be appreciated.

0
Mar 9 at 10:36 PM
User Avatarhappydev0110
#android#kotlin

Accepted Answer

Yes, but you cannot guarantee it on modern Android. When the user removes the app from the recent tasks list, Android may stop your activities and sometimes your process as well. The recommended way to keep work running is a foreground service with a persistent notification.

If you need to react when the task is removed, override onTaskRemoved() in your service:

override fun onTaskRemoved(rootIntent: Intent?) {
    // handle cleanup or restart service
}

You can also set in the manifest:

<service
    android:name=".MyService"
    android:stopWithTask="false" />

However, Android background restrictions mean the system may still stop your app, so the recommended modern approach is to use:

  • ForegroundService for continuous work

  • WorkManager for scheduled/background tasks.

In short: you can't reliably keep an app running after it is swiped away unless it uses a foreground service designed for long-running work.

User AvatarRocky Patel
Mar 10 at 6:48 AM
2