Android - implementing startForeground for a service?

前端 未结 11 1146
不思量自难忘°
不思量自难忘° 2020-11-22 06:26

So I\'m not sure where/how to implement this method to make my service run in the foreground. Currently I start my service by the following in another activity:

<         


        
11条回答
  •  感情败类
    2020-11-22 07:25

    Note: If your app targets API level 26 or higher, the system imposes restrictions on using or creating background services unless the app itself is in the foreground.

    If an app needs to create a foreground service, the app should call startForegroundService(). That method creates a background service, but the method signals to the system that the service will promote itself to the foreground.

    Once the service has been created, the service must call its startForeground() method within five seconds.

提交回复
热议问题