Android Question Callsub with waiting

Scantech

Well-Known Member
Licensed User
Longtime User
I am interested if there is anything that deals with Callsub and wait for the sub is ended. Is there any examples of this?

I need to call a sub in Main from Service. If Main is paused it will still call it and trigger the sub and wait for the sub to end.

Code:
CallSub(Main, "Testing")
'Need to wait here until the Testing Sub is Ended
 
Upvote 0
I assume that Main.Testing is a resumable sub. Otherwise you don't need to do anything special.

Code:
Sub Testing As ResumableSub
 ...

'different module
Dim rs As ResumableSub = CallSub(Main, "Testing")
if rs.IsInitialized Then
 Wait For (rs) Complete (Result As Object)
 'after
Else
 Log("Activity was paused")
End If

I thought Anything after CallSub will have to wait for the sub to be completed? But when you use CallSubDelayed it will go to next code with out waiting?

Can this be used with CallSubDelayed. I want to unpause the Main and make the call and wait for completion.
 
Last edited:
Upvote 0
Code:
Sub Service_Create
    CallSub(Main, "Testing")
    Log("After CallSub in Service")
    
End Sub

Code:
Sub Testing
    For x = 0 To 20000
        Log("TESTING IN MAIN " & x)
    Next
End Sub

This works but i need to use Callsubdelayed to unpause the activity
 
Upvote 0
Upvote 0
This is the difference with Erels Example.

'Erels Example above
Code:
Sub Service_Create
    'different module
    Dim rs As ResumableSub = CallSub(Main, "Testing")
    If rs.IsInitialized Then
        Wait For (rs) Complete (Result As Object)
        Log("AFTER WAITING")
    Else
        Log("Activity was paused")
    End If
End Sub
Code:
Sub Testing As ResumableSub
    Log("TESTING")
End Sub

'Result
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (doing) Create ***
TESTING
** Service (doing) Start **
AFTER WAITING
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
** Service (doing) Destroy **


'This Example
Code:
Sub Service_Create
    'different module
    CallSub(Main, "Testing")
    Log("AFTER WAITING")

End Sub
Code:
Sub Testing As ResumableSub
    Log("TESTING")
End Sub

'Result
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (doing) Create ***
TESTING
AFTER WAITING
** Service (doing) Start **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
** Service (doing) Destroy **

Notice the difference with **Service(doing)Start**
 
Upvote 0

Similar Threads

  • Locked
  • Article Article
Android Tutorial [B4X] SQL with Wait For
Replies
16
Views
42K
Replies
36
Views
136K
Replies
67
Views
137K
Back
Top