Reputation: 479
I startService()
a service and then bindService()
it from the same activity. Now, I'm pretty sure in the activity lifecycle that it doesn't matter if the activity is paused, stopped, or destroyed, I'm 90% sure my service persists (which is what I want). But when I press the square button (bring up the list of recent apps) and swipe the app to close it, I believe the service is paused, if not destroyed. Is this just what happens when you close an app in this fashion? And is there a way to do some code from the service before it happens?
Upvotes: 0
Views: 55
Reputation: 10308
Services are killed when the user swipes the app from recents. But if onStartCommand(...)
returned START_STICKY
, they will be restarted a few seconds later. I consider it a bug that they are killed and restarted; they should either not be killed, or killed and not restarted. I'm not sure if Google agrees.
Before the service is killed, it will get a call to onTaskRemoved(...).
Upvotes: 2