Android Question CallSubDelayed2 returned a blank value

Mahares

Expert
Licensed User
Longtime User
The object of this exercise is to use SubDelayed2 in Activity2 to display a value in MAIN activity. But the value returned is blank. I can move the sub to Main and get the value I want, but that will defeat the purpose of the exercise.
Is there any way to modify my code and stick with SubDelayed2 to display the correct value?
Thank you
'MAIN activity:
B4X:
Sub Process_Globals
    Dim MyTeam As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    StartActivity(Activity2)
End Sub

Sub GetTeam(s As String) As String
  MyTeam= "My favorite soccer team is located in " & s
End Sub

'Activity2:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    CallSubDelayed2(Main,"GetTeam","France")
    Log("My Team is: " & Main.MyTeam)   'Displays a blank value, Why???
End Sub
 

Mahares

Expert
Licensed User
Longtime User
Thanks TDS. Do you mean CallSub2(Main,"GetTeam","France") instead of using CallSub because I need to pass the parameter "France". I even tried callSub2 but it still shows blank.
 
Upvote 0

RandomCoder

Well-Known Member
Licensed User
Longtime User
I think you should stick with callsubdelayed2 which will work, but move the log statement into Activity1 immediately after setting MyTeam. Obviously you won't need to prefix it with the 'main' once in this activity. I think it will then work.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Thanks again TDS and RandomCoder. Here is the final solution that finally worked. Putting this code in Activity2:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If Not(IsPaused(Main)) Then
      CallSub2(Main,"GetTeam","France")    'CallSubDelayed2 also works
      Log("My Team is: " & Main.MyTeam)
    End If
End Sub
 
Last edited:
Upvote 0
Top