Android O Background Service Limitations

The migration guide recommends using NotificationManager.startServiceInForeground() instead of startService() if necessary.

But I do not see any startServiceInForeground() method in the NotificationManager . What am I missing?

+5
source share
3 answers

You need to change the level of the documentation site API to see new methods.

screenshot

You should use the method below suggested by @RobCo added to support library version 26.0.0-beta1

 ContextCompat.startForegroundService() 

And YES, the migration guide is wrong for this, NotificationManager does not have a method called startForegroundService() even in API 26.

PS: the migration guide has been fixed and it now binds correctly to the ContextCompat.startForegroundService() method.

+3
source

You have not missed anything. It looks like Google forgot to update the documents.

0
source

They are not yet modified in the migration guide.

You should use ContextCompat.startForegroundService() instead of the NotificationManager.startServiceInForeground() method.

0
source

Source: https://habr.com/ru/post/1270571/


All Articles