Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Q foregroundServiceType attribute

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?

like image 883
Alex.Marynovskyi Avatar asked Jul 23 '19 11:07

Alex.Marynovskyi


People also ask

What is Android foregroundServiceType?

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.

How do I start foreground priority in Android?

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.

What's a foreground notification?

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.


1 Answers

You won't be able access some APIs from the service in Android Q. Take a look at Javadoc in Android sources

like image 60
Dmytro Batyuk Avatar answered Oct 14 '22 07:10

Dmytro Batyuk