Android Question CallSubDelayed2 returned a blank value

Discussion in 'Android Questions' started by Mahares, Jan 20, 2015.

  1. Mahares

    Mahares Well Known Member Licensed 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:
    Code:
    Sub Process_Globals
        
    Dim MyTeam As String
    End Sub

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

    Sub GetTeam(s As StringAs String
      MyTeam= 
    "My favorite soccer team is located in " & s
    End Sub
    'Activity2:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
        CallSubDelayed2(Main,
    "GetTeam","France")
        
    Log("My Team is: " & Main.MyTeam)   'Displays a blank value, Why???
    End Sub
     
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    No. CallSubDelayed will be executed when the main thread is emtpy i.e. when Activity_Create stops running.
    CallSub will do an immediate call though.
     
  3. Mahares

    Mahares Well Known Member Licensed 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.
     
  4. thedesolatesoul

    thedesolatesoul Expert Licensed User

    The thing is you are trying to call one sub in another activity.
    Thinking about the activity life cycle, code in another activity cannot be executed unless it is active. And two activities cannot be active at the same time.
    Its not a matter of where the sub is 'placed'.
     
  5. RandomCoder

    RandomCoder Well-Known Member Licensed 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.
     
  6. Mahares

    Mahares Well Known Member Licensed User

    Thanks again TDS and RandomCoder. Here is the final solution that finally worked. Putting this code in Activity2:
    Code:
    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: Jan 21, 2015
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice