Why need foregroundServiceType attribute in Android Q except for location? In case a service is used for location access, we need to set it. But, what about other types? https://developer.android.com/preview/features#fg-service-types Do we really need to set them? And if not, will there be some problems or exceptions?
android:foregroundServiceType. Specify that the service is a foreground service that satisfies a particular use case. For example, a foreground service type of "location" indicates that an app is getting the device's current location, usually to continue a user-initiated action related to device location.
To create a foreground service you have to call startForeground(...) method from the Service itself passing the id of the notification and the Notification object itself. You can use the id if you want to update the notification later. I recommend you to make the service bound and bind your activity to the service.
Foreground services are an advanced Android concept which allows you to display notifications to your users when running long lived background tasks. The notification acts like any other notification, however it cannot be removed by the user and lives for the duration of the service.
You won't be able access some APIs from the service in Android Q. Take a look at Javadoc in Android sources
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