Android Question serial.connect from a class

Discussion in 'Android Questions' started by SteveTerrell, Mar 12, 2015.

  1. SteveTerrell

    SteveTerrell Active Member Licensed User

    In Main I have

    Code:
    Sub Process_Globals
        
    Dim btSerial As Serial
    and in Activity_Create
    Code:
    btSerial.Initialize("serial")
    also in Main
    Code:
    Sub serial_Connected (success As Boolean)
        
    If success Then
    etc.
    In a class, whose pointer is in Main and is initialised from Main, I want to start the connect process (btSerial.connect).

    If I do this from the class by calling a sub in Main, i.e.
    Code:
    CallSub2(Main,"Connect",meter.Mac)
    and in Main
    Code:
    Sub Connect(mac As String)
        btSerial.Connect(
    mac)
    End Sub
    then the serial_Connected sub is called as expected.

    If i do it directly from the class, i.e.
    Code:
    Main.btSerial.connect(meter.Mac)
    It compiles and at run time there is no error report (Java or otherwise) and nothing unusual in the unfiltered log, but serial_Connected is never called.

    Should this direct call work or should it have caused some sort of error report?
     
  2. SteveTerrell

    SteveTerrell Active Member Licensed User

    Ok, I understand...

    It looks like

    Main.btSerial.connect(meter.mac) when called from the class picks up the "Me" to use for the success callback as the class not Main (where it was initialised).

    Hence putting the serial_Connected sub in the class seems to work.

    So is it the general case that callback's go the calling class or activity irrespective of where the object generating the callback was initialised?
     
  3. SteveTerrell

    SteveTerrell Active Member Licensed User

    Just to confuse me....

    Dim btAdapter As BluetoothAdmin

    The state change callbacks for the adapter seem to go to Main (where it was initialised) even though the disable/enable "call" is in the class????
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Initialize it and use it from the class (or better from a service).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice