Android Question serial.connect from a class

SteveTerrell

Active Member
Licensed User
Longtime 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?
 
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?
 
Upvote 0
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????
 
Upvote 0
Back
Top