1. Download our Official Android App: Forums for Android!

Apps Persistent Bluetooth Connection Throughout the Application Lifecycle

Discussion in 'Android Development' started by Cerrberus, May 17, 2011.

  1. Cerrberus

    Cerrberus Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    May 17, 2011

    May 17, 2011
    1
    0
    5
    Hello,

    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,

    Cerb
     

    Advertisement

Share This Page

Loading...