1. Check out our companion app, Forums for Android! Download from Google Play

Same Bluetooth Connection for all Activities?

Discussion in 'Application Development' started by rich2020, Oct 5, 2011.

  1. rich2020

    rich2020 New Member
    Thread Starter
    5

    Oct 5, 2011
    1
    0
    5
    Hi all,

    New to Android, so this may seem obvious.

    Here's what I have: A class called BT_Comm
    BT_Comm creates a bluetooth connection and allows me to send data with it via a method called sendData(int xxx, int yyy);

    Now, I use this BT_Comm in my main activity -the first one.

    Say I have 10 Activities, how could I access that same BT_Comm in other Activities?

    Eg:

    -------------------------------------------------------
    Activity 1 (main)
    Code (Text):
    1.  
    2. BT_Comm bt = new BT_Comm();
    3.  
    4. pubic void someMethod()
    5. {
    6. bt.sendData(xxx, yyy);
    7. }
    -------------------------------------------------------

    Activity 2
    Code (Text):
    1.  
    2. private void someOtherMethod()
    3. {
    4. bt.sendData(xxx, yyy);
    5. }
    -------------------------------------------------------

    Activity 3
    Code (Text):
    1.  
    2. private void someOtherMethod()
    3. {
    4. bt.sendData(xxx, yyy);
    5. }
    -------------------------------------------------------

    Does anyone know how I might do this?

    Thanks,

    Rich.
     

    Advertisement

  2. alostpacket

    alostpacket Over Macho Grande?
    513

    Nov 29, 2009
    7,978
    3,606
    513
    Android App Developer
    NY
    Use a Service :)

    Check the Sample apps for BluetoothChat, it uses a "fake" service, should help you get started at least.
     

Share This Page

Loading...