Stop Android service when app is closed with the task manager

后端 未结 1 450
南笙
南笙 2021-01-05 04:31

I am working on an app with a foreground service that plays audio for an extended period of time.

I do not want the Android OS to kill my service while it\'s runni

1条回答
  •  抹茶落季
    2021-01-05 05:24

    I think that you can call stopSelf() from onTaskRemoved(). There's also a severely underdocumented android:stopWithTask you apparently can have on the element to automatically stop the service when the task is stopped from the recent-tasks list.

    Note that I haven't tried either of these, so YMMV.

    0 讨论(0)
提交回复
热议问题