B4A Class [B4X] CallSubPlus - CallSub with explicit delay

pesquera

Active Member
Licensed User
Longtime User
- Make sure to include an underscore in the target subs names if you intend to compile with obfuscation.
What could happen if not? I must to use CallSubDelayedPlus and wanted to know more about that

I noticed on ClientKVS Class that you does not include an underscore on the Sub HandleQueue, and seems to be fine compiling with obfuscation
B4X:
csu.CallSubDelayedPlus(Me, "HandleQueue", 30000)
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Hi
I know this is B4A but is this also working for B4J??
 

Dave O

Well-Known Member
Licensed User
Longtime User
This is very handy when dealing with animations.

For example, when the user opens the nav drawer and taps an item, the nav drawer typically takes ~100ms to close. When I tried updating the UI on the activity, it caused the drawer animation to stutter (because they were happening at the same time).

Using CallSubDelayedPlus, however, I give it a 150ms delay and everything is smoothy goodness.

Thanks Erel!
 

Stern0m1

Member
Licensed User
Thats what I have been doing. I think a more efficient way would just be a command to cancel. There should be a way to timer.enabled = false in the class. I just dont know anything about classes.

Thanks
 

ilan

Expert
Licensed User
Longtime User
hi,

i have a question please.

i see now that in the CallSubUtils Class in tmr_Tick
when rdd.Delayed is false then the sub will be called with CallSub and not CallSubDelayed. that make sense because this is what we want. (use CallSub and not CallSubDelayed, only in speciffic cases like calling a sub inside the same module)

but my question is, if you call a sub with CallSub and the Module is Paused then you may get a crash right?

should there not be an if statement before trying to call that sub??

this is the original code:

B4X:
Private Sub tmr_Tick
    Dim t As Timer = Sender
    t.Enabled = False
    Dim rdd As RunDelayedData = RunDelayed.Get(t)
    RunDelayed.Remove(t)
    If rdd.Delayed Then
        If rdd.Arg = Null Then
            CallSubDelayed(rdd.Module, rdd.SubName)
        Else
            CallSubDelayed2(rdd.Module, rdd.SubName, rdd.Arg)
        End If
    Else
        If rdd.Arg = Null Then
            CallSub(rdd.Module, rdd.SubName)
        Else
            CallSub2(rdd.Module, rdd.SubName, rdd.Arg)
        End If
    End If
End Sub

this is how i think it should look like (but i may be wrong)

B4X:
Private Sub tmr_Tick
    Dim t As Timer = Sender
    t.Enabled = False
    Dim rdd As RunDelayedData = RunDelayed.Get(t)
    RunDelayed.Remove(t)
    If rdd.Delayed Then
        If rdd.Arg = Null Then
            CallSubDelayed(rdd.Module, rdd.SubName)
        Else
            CallSubDelayed2(rdd.Module, rdd.SubName, rdd.Arg)
        End If
    Else
        If IsPaused(rdd.Module) Then Return 'CHECK FIRST IF MODULE IS NOT PAUSED
        If rdd.Arg = Null Then
            CallSub(rdd.Module, rdd.SubName)
        Else
            CallSub2(rdd.Module, rdd.SubName, rdd.Arg)
        End If
    End If
End Sub
 

ilan

Expert
Licensed User
Longtime User
CallSub will never crash because of a paused activity.

i could reproduce it in this simple example.

the crash is related to the timers in CallSubUtils

when you intialize callsubuitls in the starter service and then call it from 1 activity but before the timer tick was called you switch to another activity you may get this error:


what i did to solve it i check if the activity is paused, if true then it wont be called with callsub.
i also stop all timers and delete them when i exit my app. this function is important.

B4X:
Public Sub StopAll
        If RunDelayed.IsInitialized Then
            For Each tmr As Timer In RunDelayed.Keys
                tmr.Enabled = False
            Next
            RunDelayed.Clear
        End If       
End Sub

let say i want to show an ad in 2 seconds so i call csu.... now if the user exit the app then it is not relevant anymore to show that ad so i stop all timers and clear the map otherwise when he will return the timer event will be raised and i dont want that. so the StopAll function is important is some cases.
 

Attachments

  • test.zip
    5.3 KB · Views: 261

ilan

Expert
Licensed User
Longtime User
I don't see any crash here (tested in debug mode). I pressed on Show msg and then switched activity.

The error message you posted looks like a debugger error. Do you see an error in release mode?

in release mode i cant reproduce it but yesterday i am sure i got the same error in release mode.
when i returned to the app i was thrown out and i saw the same error (something with the timer in csu class)

i need to mention that i exit the app with home button. i am not sure if it is related to that.
will make more tests and let you know if i found something.

thanx, ilan
 

ilan

Expert
Licensed User
Longtime User
ok i got a crash on release mode on my app, this is the log:


EDIT: it could be because the csu was intialized in activity main, i moved it to starter service let see if i get that crash again.

btw is there a reason why the CallSubUtils "Library" (not class) does not compile on debug mode?
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…