1

I've implemented a Service that connects to a Bluetooth device and obtains data from it. I need the Service to keep alive, receiving the data, when the app is in the background. I know that I need to implement a Foreground Service, and I know how to do it. My problem is that I don't want the service's notification to show up while the Service is not connected, or when it is not live measuring, or while the user has the app opened.

So, my question would be: Can I use startForeground(int, Notification) and stopForeground(boolean) within the service, in order to move it between foreground and background?

The docu says that Services started with startForegroundService() have 5 seconds to push the notification. Is the service killed if it doesn't push the notification?

Manu Sisko
  • 269
  • 2
  • 17
  • As to your second question, I believe it will be killed if you don't call `startForeground()`, regardless of how quickly you call `stopService()`. You should bring up the notification, even if it is only for a brief moment. – greeble31 Feb 07 '20 at 22:09
  • Yes, that answers my doubts. Thank you! – Manu Sisko Feb 07 '20 at 22:23

0 Answers0