Android Question service, timer and lost ticks

pappicio

Active Member
Licensed User
Longtime User
Hi all, I have made a test, a little activity that only start a service, this service has a timer, that starts every 10 seconds, and made some checks, now, teorically, every ten seconds timer call "timer1_tick", but not ever appen:
see the code:
B4X:
#Region  Service Attributes
   #StartCommandReturnValue: android.app.Service.START_STICKY
   #StartAtBoot: True
#End Region


Sub Process_Globals
   Dim timer1 As Timer
   Dim h As String
   Dim m As String
   Dim s As String
End Sub

Sub Service_Create
   If timer1.IsInitialized = False Then
     timer1.Initialize("timer1", 10000)
   End If
   timer1.Enabled=True
   timer1_tick
End Sub
Sub timer1_tick
   
   h = DateTime.GetHour(DateTime.Now)
   If h.Length = 1 Then
     h = "0" & h
   End If
   m = DateTime.GetMinute(DateTime.Now)
   If m.Length = 1 Then
     m = "0" & m
   End If
   s = DateTime.GetSecond(DateTime.now)
   If s.Length = 1 Then
     s = "0" & s
   End If
   
   logs
End Sub

Sub logs
   
     Dim l As List
     l.Initialize
     l.clear
     Try
       l = File.ReadList(File.DirRootExternal, "logtest.txt")
     Catch
     End Try
     Dim s As String = "time: " & h & "." & m & "." & s
     l.Add(s)
     File.WriteList(File.DirRootExternal , "logtest.txt", l)
    Log("xxx")
   
End Sub

Sub Service_Start (StartingIntent As Intent)
   
End Sub

Sub Service_Destroy
   
End Sub

I can check on a txt file inside sd-card, and lost some *timer1_tick*

can someone tell me why?
the service run, all seems to be correct, why, why it losts some checks?
you can also see the log txt file on sd-card and lost checks!
(from logtest.txt on my sd-card.)
B4X:
time: 14.20.17
time: 14.20.27
time: 14.20.37
time: 14.20.47
time: 14.20.57
time: 14.21.07
time: 14.21.48 *
time: 14.22.12 *
time: 14.22.28
time: 14.22.38
time: 14.22.51 *
time: 14.23.24 *
time: 14.23.50 ***
time: 14.24.20 ***
time: 14.24.45
time: 14.25.09 **
time: 14.25.56 **
time: 14.26.06
time: 14.26.16
time: 14.26.26
time: 14.26.36
time: 14.26.46
time: 14.26.56
time: 14.27.06
time: 14.27.21 *
time: 14.28.30 *
time: 14.29.33 *
time: 14.30.19 *
time: 14.31.06
time: 14.32.00
time: 14.32.56
time: 14.33.06
time: 14.33.16

If I leave the phone connected to the log by b4a ide, all seems to work correctly, but if I unplug it, after screen off, it less a lot of check.
thanks in advances.
 
Top