Hi everyone, i'm coding an app for quite a whille (before the update), and i quitted beacuse the SO kill my foreground process while the app is in background, so after an random period of time it stop working.
I wish to know if there is a way with the new update to prevent the OS to kill my process/service
(I already tried the Erel's example of gps tracking, my phone kill even that after a while.
My phone: Meizu m5c)
it is VERY VERY ANNOYING, i can't do what i want to do, i have to verify if a person is in a determinate place until the users decide to close the app himself.
But if the OS kill the app when it want, so i can't develop my app correctly....
it is VERY VERY ANNOYING, i can't do what i want to do, i have to verify if a person is in a determinate place until the users decide to close the app himself.
But if the OS kill the app when it want, so i can't develop my app correctly....
You can have your service running in the background but you need to create a foreground service and a notification will show the whole time until you or the user decides to kill the device.
Do a search for foreground services.
You can have your service running in the background but you need to create a foreground service and a notification will show the whole time until you or the user decides to kill the device.
Do a search for foreground services.
This is implemented in the background location tracking example linked above. Not all devices let foreground services to be kept alive for a long time.
This works for me, i run an app that uses Gps for up to 15Hrs a day 6 days a week with no problems.
This is all in a Service
This in Service Create
B4X:
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
This in Service
B4X:
Sub Service_Start (StartingIntent As Intent)
Service.StartForeground(nid, CreateNotification("..."))
StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, False)
End Sub
B4X:
Sub CreateNotification (Body As String) As Notification
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_HIGH)
notification.Icon = "icon"
notification.SetInfo("App Title", Body, Main)
Return notification
End Sub
You can have your service running in the background but you need to create a foreground service and a notification will show the whole time until you or the user decides to kill the device.
Do a search for foreground services.
Yeah, i discovered that thing yesterday, but my phone killed also that one, but now i realized that maybe i have to start the service as foreground service right? Because the original code doesn't.
I tried with 15minutes, but it was killed anyway.
Now i'm trying with an interval of 30 minutes just in case (but the purpose of the app it's count how many time a person stay in a determinate place, if the precision is +-30min it is very imprecise)