Android Question Service to activity label

Pedro Caldeira

Active Member
Licensed User
Longtime User
Hi,
I am trying to send some text from a sub in a service to a label in the activity.
I always get an error

Service
B4X:
Sub WinRESTSocket_NewConnection (Successful As Boolean, NewSocket As Socket)

    If Successful Then
        IncomingStream.Initialize(NewSocket.InputStream, NewSocket.OutputStream, "IncomingStream")
        CallSubDelayed2(Main,"ShowLog","Connected to WinREST")
    End If
    WinRESTSocket.Listen

End Sub

Activity
B4X:
Sub ShowLog(Text2show As String, clear As Boolean)
    If clear = True Then
        lblStatus.text=""
    Else
        lblStatus.text = lblStatus.text & Text2show & CRLF
    End If
End Sub

Error
B4X:
-------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (CallSubDelayed - ShowLog)
running waiting messages (1)
An error occurred: 
(Line: 61) End Sub
java.lang.Exception: Sub showlog signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject p2g.Wrst2Zarph.main_subs_0._showlog(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception

class anywheresoftware.b4a.pc.RemoteObject,
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Error:
java.lang.Exception: Sub showlog signature does not match expected signature.
Cause:
CallSubDelayed2(Main,"ShowLog","Connected to WinREST")

You're expecting two parameters, a string and a Boolean and you're only passing a string. Also, you should probably change the name of the sub to "Show_Log" if you plan to obfuscate the project at some point.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
This is the signature from callsubdelayed2

CallSubDelayed2 (Component As Object, Sub As String, Argument As Object)

The last parameter is an OBJECT. You only can give ONE parameter.
You are giving a String here....

B4X:
CallSubDelayed2(Main,"ShowLog","Connected to WinREST")
But your sub needs two parameters... So i suggest to use a List or a Map as Parameter and get the right values out of the List/Map.

Additionally you should have an underscore in the subname if you plan to compile obfuscated.

B4X:
dim m as map = CreateMap("Text2Show":"MyText","Clear":true)
CallSubDelayed2(Main,"Show_Log",m)


B4X:
Sub Show_Log(cfg as Map)
    dim text2show as string = cfg.get("Text2Show")
    dim clear as boolean = cfg.get("Clear")   
If clear = True Then
        lblStatus.text=""
    Else
        lblStatus.text = lblStatus.text & Text2show & CRLF
    End If
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I know; it was just to inform HIM that CallSubDelayed exists
My answer was NOT meant to YOU! I´m NOT INTERESTED in anything you write (say it layoutproblems, nullpointer exceptions or whatever). You are on my ignorelist. So basically i do not see such posts. But sometime i reveal the post...

Don´t expect any answer from me (expect this one) to be a answer to your post!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…