Android Question Wait for timer event

Discussion in 'Android Questions' started by rossati, Jun 7, 2019.

Tags:
  1. rossati

    rossati Active Member Licensed User

    I would like to execute some code and wait for it to complete, but I can't use Wait For sub because my application is not monolithic, so I'm trying the Timer, that is when the application ends, I start a timer for some time hoping that this may be intercepted.
    Unfortunately this does not work: is it a conceptual error or simply a syntax error?
    Code:
    Sub fgw(activ As Activity,params As String,handleSub As String)
        resumable = 
    True
        fg_timer.Initialize(
    "fg_timer",100)
        fg(activ,params,
    "",handleSub)
        
    Wait for fg_timer_Tick   
        fg_timer.Enabled = 
    False
    End Sub
    ...
        
    If resumable Then
             fg_timer.Enabled = 
    True
             
    Return
        
    End If
    Thanks
     
  2. agraham

    agraham Expert Licensed User

    Care to explain what this means?
     
  3. rossati

    rossati Active Member Licensed User

    Thank agraham, not monolithic means that in my application I call a sub that calls other subs and it is this last that must be awaited, but it seems that Wait For can't make this.
    En passant I haven't find a site whit the syntax of Wait For.
     
  4. agraham

    agraham Expert Licensed User

    I'm still not sure what you mean but the first sub can Wait For the second which can Wait For the third and so on.

    Have you watched the 'Resumable Subs' tutorial ?
    https://www.b4x.com/etp.html
     
  5. MarkusR

    MarkusR Well-Known Member Licensed User

    its similar testing a flag in a timer event.
    enable timer
    tick event
    if flag then do something: end timer


    for longer sub routines you still need a sleep call that the event loop continues.
     
  6. rossati

    rossati Active Member Licensed User

    Yes I have
    My application is a Form Generator (that you can download from my site www.condorinformatique.com).
    I call the Form generator passing the name of the sub for manage the data inserted in the form:
    Code:
    txtParams.Text = "Title,Title,Views creation;" _
                           & 
    "Ground,FF0000FF FF404040;" _
                           & 
    "T,Field,Label field,20,,Insert some text;S,Seek bar,,5,36.5,20 93;" _
                           & 
    "CMB,cmb,Combo box,20,,Alpha|Beta|Delta|Gamma;" _
                           & 
    "CKB,Check,,15;R,Rdb2,Status2,,Single,M:Married|S:Single|W:Widow;After,Check,cmb"
    fg.fg(
    Activity,txtParams.Text,Me,"handleAnswerTest","handleEvents")
    ' here i would process the form's data
    ...
    I would to avoid the use of this sub (handleAnswerTest in the code above)and process the data in the same sub that requested the creation of the form, but
    unfortunately fg.fg makes a callsubdelayed to a sub that creates the form and exits. In other words if I wait fg.fg the wait finish before the form creation.
     
  7. agraham

    agraham Expert Licensed User

    If you have control over the Sub called by CallSubDelayed then why not pass a callback to that Sub and have it call it when the form is available?
     
  8. MarkusR

    MarkusR Well-Known Member Licensed User

    and without callsubdelayed,Resumable,sleep it takes so long time?

    cascading resumable subs
    Code:
    Sub Test
        
        
    Log("Test Start")
        
    Wait For (Depth1) Complete (Result As Boolean)
        
    Log("Result=" & Result)
        
    Log("Test End")
        
    End Sub

    Sub Depth1 As ResumableSub
        
        
    Wait For (Depth2) Complete (Result As Boolean)
        
    Return Result
        
    End Sub


    Sub Depth2 As ResumableSub
        
        
    Wait For (Depth3) Complete (Result As Boolean)
        
    Return Result
            
    End Sub

    Sub Depth3 As ResumableSub
        
        Sleep(
    0)
        
        
    Log("Depth3 Ready")
        
        
    Return True
        
    End Sub
     
  9. rossati

    rossati Active Member Licensed User

    I want to add a function to generate the form, wait for the conclusion and continue in the same sub that asked for the creation of the form.
     
  10. MarkusR

    MarkusR Well-Known Member Licensed User

    that was my example showing.

    u need this wait for , resumable subs only if your sub would block the main thread and the app would not response for the user.
    just creating a form at runtime should not take a long time.
    maybe u misapply CallSubDelayed?
     
    Last edited: Jun 8, 2019
  11. rossati

    rossati Active Member Licensed User

    Thanks MarcusR your suggestion, I think, can works; but I wouldn't disseminate the form generator of Wait For even because the form generator is rather complex.
    The timer seemed to me the simplest solution, provided that Wait For waits even when the timer is disabled.
     
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