0

I have set up an RxAndroidBle Observable/Subscriber to receive and log data from several Bluetooth LE peripherals. It is inside an Android Service, which currently is of the Bound variety (to 2 different Activities).

I was planning to add the "Started Service" features to this Service so it could continue to run when the Activities are suspended, but in early tests it looks like this isn't necessary: it seems to continue running when the App is in the background. I don't understand why this works, because the Android docs say that when all Activities unbind from a Bound Service, it will be destroyed (both of my Activities call unbind() in their onStop() methods).

What's going on here? Is the existence of an active Observable somehow keeping the Service alive? What, if anything, should I do to manage this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Robert Lewis
  • 1,847
  • 2
  • 18
  • 43
  • Did you check if onDestroy() of the Service is called when you unbind? – Steve M Jan 05 '18 at 21:00
  • It appears that `onDestroy()` of the `Service` is not being called. – Robert Lewis Jan 06 '18 at 00:33
  • Wondering if `onDestroy()` isn't being called simply because Android hasn't gotten around to it yet. Can it come along at any moment and tank my Service? – Robert Lewis Jan 13 '18 at 17:41
  • Dariusz Seweryn: Would really like to get a response from Polidea on this – Robert Lewis Jan 17 '18 at 20:45
  • No onDestroy is called at a determinate time. Might be garbage collected later though if possible. Are you sure service is not started some other way. – Steve M Jan 17 '18 at 20:51
  • The app has 2 activities. They both bind to the service in the typical way, and unbind in either `onStop()` or `onDestroy()`. No command (that I can find) is ever called to start the service. Yet the Observables keep running merrily along when the app is backgrounded. I'm not complaining: this is the desired behavior. I'd just like to understand why it works without the service ever being formally started. – Robert Lewis Jan 17 '18 at 21:06
  • Try it without observables and see if onDestroy is called. Post minimum test case on github if possible. – Steve M Jan 19 '18 at 20:23

0 Answers0