Has anyone experienced timer ticks not firing when they should under Android 12. I am currently running some tests on this. This has been noticed in a background service and a class instanced within a long running background service.
Attached is log data from the app that show when the ticks occur. The tick should occur every 5 seconds, and every 45 seconds a heartbeat (PING) is sent and the response received. There should be 9 tmrhook_tick events between each 'Send Heartbeat'. You can easly see this is not the case. LIne 350 in the attachment is a very good example of this.
Yes, I always use a foreground service. This is a summary of the service lifesycle, svc_service
B4X:
Sub Service_Create
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
pw.PartialLock
end sub
Sub Service_Start (StartingIntent As Intent)
Service.StartForeground(nID,CreateNotification("Atlas PTT","Offline","icon_offline",Main,False,False))
end sub
Sub Service_Destroy
Service.StopAutomaticForeground
pw.ReleasePartialLock
End Sub
Within this I call the folllowing:
B4X:
Sub load_channel_listeners
Dim rs As ResultSet
' // 2021.03.12 - only load listeners that we have access too.
Try
ChannelListen.Initialize
rs = Main.SQLDB.ExecQuery($"
SELECT DISTINCT * FROM ptt_channel_listen
INNER JOIN ptt_users_channels ON ptt_channel_listen.channel_id=ptt_users_channels.channel_id
"$)
Do While rs.NextRow
Dim c As cls_channel_listen, id As Int
id = rs.GetInt("channel_id")
If ChannelListen.ContainsKey(id) Then
listenChannel_remove(id)
ChannelListen.Remove(id)
End If
If Not(ChannelListen.ContainsKey(id)) Then
' // create a listen instance
ChannelListen.Put(id,c)
c.Initialize(id)
c.enabled = True
End If
Loop
rs.close
Catch
log($"svc_service::load_channel_listeners() error - ${LastException.Message}"$)
End Try
End Sub
cls_channel_listen has a timer in it with an interval of 5000 ms
I suspect you are right. Myself and @OliverA looked at the timer lib and the postDelayed method and it all pointed back to the cpu. The app still functions. It is somthing to be aware of I guess when an app is in background.