• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Persistent Bluetooth Connection Throughout the Application Lifecycle


May 17, 2011

I have developed an application that does payments processing, and hooks to a card swipe/printer device via bluetooth. I can print receipts fine, and I can accept and parse the magnetic swipe data fine. I only have one problem: the application drops the bluetooth connection between views. For each activity that uses the device, I have to re-pair with the device. I've automated this to keep the device MAC in the preferences and the user only has to put up with a 2-5 second delay, but there has to be a better way.

I have incorporated the Bluetooth Chat Example from the Android website into the project and made modifications for the specific serial connection to the printer. I've tried also modifying it to be an actual service running in the background, but then I run into another problem where connection to the device is never stopped, and any further attempts to read or write from the service threads do not work.

Likely the problem is me. I need help deciding how to handle this architecturally. How can I pair with the Bluetooth device on app start and keep coming back to that service to write or read data from multiple activities? Is there a way to share and pass threads between activities? Any advice is welcome.

Thank you,



We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.