If a task is destroyed in the background and the activity stack is later restored, are services originally started by that task also restored? More specifically, will they be restarted in this situation even if their onStartCommand(...)
returned START_NOT_STICKY
?
I'm asking because setting android:alwaysRetainTaskState
to false does not guarantee that task state will not be retained. I'm concerned that if my task is killed and restored, the top activity may be one that depends on services conditionally started by the launcher activity. I considered the solutions suggested on this question and the other one. But then it occurred to me that if the services will be automatically restarted, I don't need to worry about it. (And the fact that services are running may help keep the app alive anyway, so this may be an extreme edge case if it's a concern at all.)
I want to avoid START_STICKY
because it causes services to be restarted without a task a few seconds after they're killed. (At least, this is what happens when the app is swiped from recents.) They shouldn't be restarted until the task is restored.