0

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.

Community
  • 1
  • 1
Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
  • this depends on what is returned http://developer.android.com/intl/ko/reference/android/app/Service.html#START_NOT_STICKY – QAMAR Aug 02 '15 at 07:55
  • @QAMAR I'm hoping to avoid using `START_STICKY` because it creates another problem. If the app is swiped from recents, [the service is restarted](http://stackoverflow.com/a/18618060/1953590) a few seconds later without any task associated with it. – Kevin Krumwiede Aug 02 '15 at 08:16
  • see other constants like START_FLAG_RETRY START_REDELIVER_INTENT etc – QAMAR Aug 02 '15 at 08:18
  • @QAMAR `START_FLAG_RETRY` doesn't seem relevant, and `START_REDELIVER_INTENT` behaves in the same problematic way as `START_STICKY`. – Kevin Krumwiede Aug 02 '15 at 08:21

0 Answers0