Android Question anywheresoftware.b4a.keywords.Common.CallSub4

D

Deleted member 103

Guest
Hi,

here's a mistake (of many) I do not understand.
Is triggered by this code, but why?
B4X:
Sub GpsTimer_Tick
    Dim IntervalNext As Double
    Dim time As Long
    Dim DistanceTheoretically As Double
    DateTime1 = DateTime.Now
    time      = DateTime1 - lngTimer

    If Not(IsPaused(Main)) Then
        CallSub2(Main, "ShowClocktime", DateTime.time(time))
    End If
...
crash_1.JPG
 
D

Deleted member 103

Guest
How are you building the layout?
The layout has been created with the designer.

Can this be the error because the Timer is started by Starter Service?
B4X:
Sub Service_Create
    GpsTimer.Initialize("GpsTimer", 100) '20)
    GpsTimer.Enabled=True
End Sub

Should it be better that way?
B4X:
Sub Service_Create
    GpsTimer.Initialize("GpsTimer", 100) '20)
End Sub

Sub Service_Start (StartingIntent As Intent)
    GpsTimer.Enabled=True
End Sub
 
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
B4X:
time      = DateTime1 - lngTimer
you calculate with time, is 'time' a valid time?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
@Filippo can you upload a small project that demonstrates that issue?

btw why are you running a timer in starter service when you want to update a label in main activity?

why not run it in main activity? like this it will only run when your main activity is active.
 
Upvote 0
D

Deleted member 103

Guest
I've changed the way the error is handled internally in the case of CallSub for the next version of B4A. The crash report will be more meaningful.

@Filippo If you like send me an email and I'll send you the updated core.
Thank you Erel, it is not necessary, I have solved it differently.
I'm updating my label "lblClock" with an extra timer in the main activity, and no longer using the starter service.

@ilan
The appendix is an example.

I have found that the starter service, if the main activity is in pause, triggers too much event, and this is probably the error.
Try one time
B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now
   
    'If Not(IsPaused(Main)) Then CallSub2(Main, "ShowClock", time)
   
    CallSub2(Main, "ShowClock", time)
   
End Sub

and once so and look at the unfiltered events.
B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now
   
    If Not(IsPaused(Main)) Then CallSub2(Main, "ShowClock", time)
   
    'CallSub2(Main, "ShowClock", time)
   
End Sub

As it seems, you always have to check before a CallSub whether an activity is paused.
 

Attachments

  • TestTimer.zip
    7.7 KB · Views: 200
  • b4a_ignoring_event.txt
    921 bytes · Views: 172
Upvote 0

ilan

Expert
Licensed User
Longtime User
Thank you Erel, it is not necessary, I have solved it differently.
I'm updating my label "lblClock" with an extra timer in the main activity, and no longer using the starter service.

@ilan
The appendix is an example.

I have found that the starter service, if the main activity is in pause, triggers too much event, and this is probably the error.
Try one time
B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now
  
    'If Not(IsPaused(Main)) Then CallSub2(Main, "ShowClock", time)
  
    CallSub2(Main, "ShowClock", time)
  
End Sub

and once so and look at the unfiltered events.
B4X:
Sub GpsTimer_Tick
    Dim time As Long
    time = DateTime.Now
  
    If Not(IsPaused(Main)) Then CallSub2(Main, "ShowClock", time)
  
    'CallSub2(Main, "ShowClock", time)
  
End Sub

As it seems, you always have to check before a CallSub whether an activity is paused.

the example works for me. i still would do it differently.
why are you using a timer from the starter service?
why not use that timer in the activity that should show the output of that timer_tick??
 
Upvote 0
D

Deleted member 103

Guest
why are you using a timer from the starter service?
why not use that timer in the activity that should show the output of that timer_tick??
Because it should actually go and because I spare some timer and everything is central.
But saving, as it looks, is not always a good solution. :)
 
Upvote 0
Top