Android Question Callsub2(VarObj,VarSubr,s)

rosippc64a

Active Member
Licensed User
Longtime User
I encountered a problem, and can't solve it.
I have a service. It is reading from usb. I would like use it from different activities. When data is arrived the service calls the caller activity's subrutine.

Service:
---------------------------------------
B4X:
Sub Process_Globals
    ...
    Dim CallObj As Object = Null
    Dim CallSubr As String = ""
    ...
end sub.
Sub Astreams1_NewData (Buffer() As Byte)
      ... s = read data
       CallSub2(CallObj,CallSubr,s)
end sub
Activity:
--------------------------------------------------------
B4X:
...
Sub Activity_Create(FirstTime As Boolean)
    ANTENNA.CallObj = Activity
    ANTENNA.CallSubr = "SubAnt"
    StartService("ANTENNA")
end sub
Service starts ok, but when service callsub2 is reached, I get error:
"java.lang.RuntimeException: java.lang.ClassCastException: anywheresoftware.b4a.BALayout cannot be cast to java.lang.String"
Can I add variable to the Callsub2 2nd param ?

----------
SOLVED
----------
B4X:
...
Sub Activity_Create(FirstTime As Boolean)
    ANTENNA.CallObj = Activity -> instead of Activity -> Me -> even better "Activity name"
    ANTENNA.CallSubr = "SubAnt"
    StartService("ANTENNA")
end sub
 
Last edited:
Top