To the eye, it may seem like your Android application is “dead” when you “kill” the app via the task manager, but you may be surprised that in many cases, the application process lives on.
Here are some ADB commands that you can diagnose and investigate what’s going on, on the device.
Determine Running Processes via ADB
adb shell ps
adb shell ps | grep com.mydomain.myappnamegoeshere
An Android Service registered to your application will prevent your process from being killed if it is currently running. Therefore you need to be careful and aware that your singleton variables in your application are aware of this. Read more about this here: Processes and Application Life Cycle.
void onTaskRemoved (Intent rootIntent)
You can leverage the Service::onTaskRemoved() method in Android to catch this “swipe” event where the user intends to “kill” your app via the task manager, even if services continue to run in the background. This can be useful to catch this event if you want to end a user session for instance. This can also be useful if your intention is to stop services when the user dismisses your app, as you can programatically stop the service at this point in time as well.
Note: If you have set ServiceInfo.FLAG_STOP_WITH_TASK when starting the Service, then you will not receive this callback; instead, the service will simply be stopped.