weliem / blessed-android

BLESSED, a Bluetooth Low Energy (BLE) library for Android
MIT License
556 stars 120 forks source link

Keeping Bluetooth in the background? #36

Closed DrEdHepler closed 4 years ago

DrEdHepler commented 4 years ago

Thanks for this package! It looks like it could make using BLE much easier in my application. Since my application has a significant user interface, and Android suggests that the UI activity be in the foreground for best performance, I'm wondering if you have thoughts on the changes necessary (or a version already exists?) where bluetooth (central) runs in the background as a service? I'm hoping the BLE central will run in the background (collecting data) and make it available from the service. Thoughts on the changes needed? Thanks...

weliem commented 4 years ago

I have done it in the past using a foreground Service. In that service you create your Central etc. You need too make sure you take into account that your app might not (yet) be running yet. So communicating via broadcasts would be the safest.

I don't have an example to share, but I'll consider doing one....