Sub Button1_Click
'This call will bring Activity2 to front and will then execute ShowList
If SubExists("Activity2", "ShowList") Then ' don't works
' If SubExists(Activity2, "ShowList") Then ' don't works
CallSubDelayed3("Activity2", "ShowList", "Main", "This is the title")
End If
End Sub
SubExists returns False in both ways, with or without quote.
Activity2:
B4X:
Public Sub ShowList(Caller As String, Title As String)
mCaller = Caller
Activity.Title = Title
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
'this call will bring Main to front and call GetResult
If SubExists(mCaller, "GetResult") Then
CallSubDelayed2(mCaller, "GetResult", Value)
End If
End Sub
You don't need to use SubExists. Nothing happens if the sub doesn't exist.
See SubExists documentation:
Tests whether the object includes the specified method.
Returns false if the object was not initialized or not an instance of a user class.
(I removed the post from the other thread. It is not relevant to that thread)
My previous answer was incorrect.
SubExists returns False because the second activity was not yet created.
CallSubDelayed does throw an error if the target sub doesn't exist. This is by design. You will also see a warning about it. This is the same as trying to directly call a sub that doesn't exist
If you want to implement an event then you should usually use CallSub. CallSub doesn't do anything if the target sub (in the activity or service) doesn't exist.
Isnt CallSubDelayed supposed to start the target activity/service? This is why I use it to raise events in different activities.
I also have to use CallSubDelayed when raising events on UI thread, as some events (like touch,onResult etc) cause issues with MsgBox etc.
I always thought it is much safer than CallSub.