Android Question Problem with CallSub

HARRY

Active Member
Licensed User
Longtime User
I have a project with several activities.
The main activity, called Main takes care of a.o. asyncstreamtext. Sending is done as follows
B4X:
Public Sub Send (Mess As String)
    If Stream1.IsInitialized = False Then  Stream1.Initialize(Me,"Stream1",Client1.InputStream,Client1.OutputStream)  'to Raspberry
    Stream1.Write(Mess&CRLF)
   
End Sub



Another activity also has to send some data.I tried to do so, based on sampl code which I do not completely understand, as follows:
B4X:
Sub sendrequest(text As String)
Dim request As Object= text
    Dim jo As JavaObject =request
    CallSub2(Main,"send",jo)
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
If you are in activityX then you cannot start a sub in main activity (it is paused!)
Use CallSubDelayed to start main activity and the sub.

Better use a service to do all the asyncstream-things... Call the sub in the service then.
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Thanks Erel and DonManfred!


I moved everything about asyncstreams to a Service module. But I still have problems to get the information I want to send correctly sent to the other side.

In the main module eg. I write:

B4X:
mcode=15
Dim request As Object= mcode & s   'two variables, s="|"
Dim jo As JavaObject =request
CallSub2(StreamService,"send",jo)

This gives java errors. I tried several other formats; some really send information, but the receiving side then get the text "String 15|"

The service module has the code:

B4X:
Public Sub Send (Mess As String)
    If Stream1.IsInitialized = False Then  Stream1.Initialize(Me,"Stream1",Client1.InputStream,Client1.OutputStream)  'to Raspberry
    Stream1.Write(Mess&CRLF)  
End Sub

Could somebody correct these small pieces of code! Please.

Harry
 
Upvote 0
Top