How to prevent android service getting killed (Service with notification)

前端 未结 4 1302
太阳男子
太阳男子 2021-01-22 23:15

I am working on an application which need to show notification constantly.
I\'ve a service to show the notification every seconds.
When the resources goes low android is

4条回答
  •  清歌不尽
    2021-01-22 23:48

    Update:

    You can use Foreground Service in the scenario. From the docs:

    A foreground service is a service that's considered to be something the user is actively aware of and thus not a candidate for the system to kill when low on memory. A foreground service must provide a notification for the status bar, which is placed under the "Ongoing" heading, which means that the notification cannot be dismissed unless the service is either stopped or removed from the foreground.


    In my knowledge there is no bulletproof way of preventing your service from being stopped by the android system. If the device is critical on memory/resources then your service has to be stopped for GC. This is also not recommended because your service will drain the device battery.

提交回复
热议问题