In the migration guide it is suggested that we use NotificationManager.startServiceInForeground()
instead of startService()
when necessary.
But I cannot see any startServiceInForeground()
method in NotificationManager
. What am I missing?
IntentService is subject to these restrictionsIntentService is a service, and is therefore subject to the new restrictions on background services. As a result, many apps that rely on IntentService do not work properly when targeting Android 8.0 or higher. For this reason, Android Support Library 26.0.
There is a option called standard limit which means you want to run about 20 processes in your background. If having problem scroll:How to limit background processes in an android smartphone?
A background service performs an operation that isn't directly noticed by the user. For example, if an app used a service to compact its storage, that would usually be a background service.
Background Service Limitations: While an app is idle, there are limits to its use of background services. This does not apply to foreground services, which are more noticeable to the user.
To lower the chance of these problems, Android 8.0 places limitations on what apps can do while users aren't directly interacting with them. Apps are restricted in two ways: Background Service Limitations: While an app is idle, there are limits to its use of background services.
Apps are restricted in two ways: Background Service Limitations: While an app is idle, there are limits to its use of background services. This does not apply to foreground services, which are more noticeable to the user.
Broadcast Limitations: With limited exceptions, apps cannot use their manifest to register for implicit broadcasts. They can still register for these broadcasts at runtime, and they can use the manifest to register for explicit broadcasts targeted specifically at their app.
You need to change the API level of documentation site to see the new methods
You should use the below method suggested by @RobCo added in the 26.0.0-beta1 support library release
ContextCompat.startForegroundService()
And YES, the migration guide for this is wrong, NotificationManager doesn't have a method called startForegroundService()
even in API 26.
PS: The migration guide has been corrected, and now it links correctly to the ContextCompat.startForegroundService()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With