Hi Guys,
need some help. I have a Service that is started and stopped from UI (similar to B4A Bridge). Upon "Start" button pressed I do a "StartService("MyService") and upon "Stop" button I do a "StopService("MyService"). this is (simplified the Service_Create :
Everything works fine and in most of cases the service once started it keeps running in background and do its job for hrs and hrs with no issues. Unfortunately I have some users complaining that in some cases the service just disappear. I think that can only mean 2 things:
1- the service crashes
OR
2- Android decides to kill it form some reasons.
For 1 I have bee trying to trace it for months looking at the Google play logs but could not find anything that helped, especially because I could never reproduce it on any of my phones (different phones, different Android versions) . For 2 I have no clue either.
Some questions:
1- I have read on one of Erel's tutorial that using AUTOMATIC_FOREGROUND_ALWAYS I should also acquire a partial wake lock. Actually I did not do that. do you think it may help?
2- what about scheduling an additional StartServiceAt service that monitors the main service and in case it finds it IsPaused = true (i.e not running) it starts it again? Would that help in case of the main service is killed by Android or in that case Android would kill the periodic monitor service too?
3 - is there a way to create a log upon service crash or in case the service is killed by the OS ?
thanks for your help..
need some help. I have a Service that is started and stopped from UI (similar to B4A Bridge). Upon "Start" button pressed I do a "StartService("MyService") and upon "Stop" button I do a "StopService("MyService"). this is (simplified the Service_Create :
B4X:
Sub Service_Create
'some code............'
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
Service.AutomaticForegroundNotification = CreateNotification("xxx" ,"my service","main",False,False)
Service.StartForeground(0, Notification1)
' start the main service task here: do something and send/cancel notifications if needed
End Sub
Sub Service_Destroy
'...............'
Service.StopAutomaticForeground
End Sub
Everything works fine and in most of cases the service once started it keeps running in background and do its job for hrs and hrs with no issues. Unfortunately I have some users complaining that in some cases the service just disappear. I think that can only mean 2 things:
1- the service crashes
OR
2- Android decides to kill it form some reasons.
For 1 I have bee trying to trace it for months looking at the Google play logs but could not find anything that helped, especially because I could never reproduce it on any of my phones (different phones, different Android versions) . For 2 I have no clue either.
Some questions:
1- I have read on one of Erel's tutorial that using AUTOMATIC_FOREGROUND_ALWAYS I should also acquire a partial wake lock. Actually I did not do that. do you think it may help?
2- what about scheduling an additional StartServiceAt service that monitors the main service and in case it finds it IsPaused = true (i.e not running) it starts it again? Would that help in case of the main service is killed by Android or in that case Android would kill the periodic monitor service too?
3 - is there a way to create a log upon service crash or in case the service is killed by the OS ?
thanks for your help..