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

Apps Same Bluetooth Connection for all Activities?

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

  1. rich2020

    rich2020 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Oct 5, 2011

    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?
    Rank:
    None
    Points:
    513
    Posts:
    7,973
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,973
    3,603
    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...