M Mike1970 Well-Known Member Licensed User Longtime User Oct 18, 2019 #1 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) Last edited: Oct 18, 2019
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)
Brandsum Well-Known Member Licensed User Oct 18, 2019 #2 https://www.b4x.com/android/forum/threads/99873 Upvote 0
M Mike1970 Well-Known Member Licensed User Longtime User Oct 18, 2019 #3 Brandsum said: https://www.b4x.com/android/forum/threads/99873 Click to expand... Mike1970 said: (I already tried the Erel's example of gps tracking, my phone kill even that after a while. Click to expand... Upvote 0
Brandsum said: https://www.b4x.com/android/forum/threads/99873 Click to expand... Mike1970 said: (I already tried the Erel's example of gps tracking, my phone kill even that after a while. Click to expand...
M Mike1970 Well-Known Member Licensed User Longtime User Oct 18, 2019 #5 Brandsum said: What is the android version? Click to expand... Android 6.0 Upvote 0
Brandsum Well-Known Member Licensed User Oct 18, 2019 #6 Did you get any log when the service stop working? Is there any other app in your device that runs in the background without any issue? Upvote 0
Did you get any log when the service stop working? Is there any other app in your device that runs in the background without any issue?
M Mike1970 Well-Known Member Licensed User Longtime User Oct 18, 2019 #7 Brandsum said: Did you get any log when the service stop working? Is there any other app in your device that runs in the background without any issue? Click to expand... No, any log, the OS kills all the services silently. For example in settings>Apps>Now i can see what apps/services are running and the time elapsed from opening. My app there isn't because it was killed after 2/3 hours, but the other apps are still running after 6+ hours at this point Upvote 0
Brandsum said: Did you get any log when the service stop working? Is there any other app in your device that runs in the background without any issue? Click to expand... No, any log, the OS kills all the services silently. For example in settings>Apps>Now i can see what apps/services are running and the time elapsed from opening. My app there isn't because it was killed after 2/3 hours, but the other apps are still running after 6+ hours at this point
M Mike1970 Well-Known Member Licensed User Longtime User Oct 18, 2019 #8 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.... Last edited: Oct 18, 2019 Upvote 0
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....
walterf25 Expert Licensed User Longtime User Oct 19, 2019 #9 Mike1970 said: 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.... Click to expand... 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. Walter Upvote 0
Mike1970 said: 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.... Click to expand... 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. Walter
Erel B4X founder Staff member Licensed User Longtime User Oct 19, 2019 #10 walterf25 said: 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. Click to expand... 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. Trying adding geofence features: https://www.b4x.com/android/forum/threads/84767/#content Upvote 0
walterf25 said: 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. Click to expand... 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. Trying adding geofence features: https://www.b4x.com/android/forum/threads/84767/#content
DonManfred Expert Licensed User Longtime User Oct 19, 2019 #11 OffTopic walterf25 said: show the whole time until you or the user decides to kill the device. Click to expand... THAT is not a good idea to kill the DEVICE instead of the App. Upvote 0
OffTopic walterf25 said: show the whole time until you or the user decides to kill the device. Click to expand... THAT is not a good idea to kill the DEVICE instead of the App.
D dgoss Member Licensed User Longtime User Oct 19, 2019 #12 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 Code: Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves This in Service Code: Sub Service_Start (StartingIntent As Intent) Service.StartForeground(nid, CreateNotification("...")) StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, False) End Sub Code: 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 Upvote 0
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 Code: Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves This in Service Code: Sub Service_Start (StartingIntent As Intent) Service.StartForeground(nid, CreateNotification("...")) StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, False) End Sub Code: 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
walterf25 Expert Licensed User Longtime User Oct 19, 2019 #13 DonManfred said: OffTopic THAT is not a good idea to kill the DEVICE instead of the App. Click to expand... I've already had one too many beers. I meant kill the service Walter Upvote 0
DonManfred said: OffTopic THAT is not a good idea to kill the DEVICE instead of the App. Click to expand... I've already had one too many beers. I meant kill the service Walter
M Mike1970 Well-Known Member Licensed User Longtime User Oct 19, 2019 #14 walterf25 said: 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. Walter Click to expand... It's alrady a foreground service, that part is taken from @Erel example. It's that the problem...i don't know what to do anymore Upvote 0
walterf25 said: 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. Walter Click to expand... It's alrady a foreground service, that part is taken from @Erel example. It's that the problem...i don't know what to do anymore
M Mike1970 Well-Known Member Licensed User Longtime User Oct 19, 2019 #15 dgoss said: 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 Click to expand... Yes, this is the code implemented in Erel's example, right? The only difference with yours is that I set Code: notification.IMPORTANCE_LOW instead of Code: notification.IMPORTANCE_HIGH And that i restart the service every 10 minutes instead of 30 Last edited: Oct 19, 2019 Upvote 0
dgoss said: 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 Click to expand... Yes, this is the code implemented in Erel's example, right? The only difference with yours is that I set Code: notification.IMPORTANCE_LOW instead of Code: notification.IMPORTANCE_HIGH And that i restart the service every 10 minutes instead of 30
M Mike1970 Well-Known Member Licensed User Longtime User Oct 19, 2019 #16 dgoss said: This works for me, i run an app that uses Gps for up to 15Hrs a day 6 days a week with no problems. Click to expand... What smartphone have you tried? Upvote 0
dgoss said: This works for me, i run an app that uses Gps for up to 15Hrs a day 6 days a week with no problems. Click to expand... What smartphone have you tried?
M Mike1970 Well-Known Member Licensed User Longtime User Oct 19, 2019 #17 Erel said: Trying adding geofence features Click to expand... 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. Upvote 0
Erel said: Trying adding geofence features Click to expand... 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.
udg Expert Licensed User Longtime User Oct 19, 2019 #18 And that i restart the service every 10 minutes instead of 30 Click to expand... This could be part of the problem. You're not expected to restart a service in such a short time. Upvote 0
And that i restart the service every 10 minutes instead of 30 Click to expand... This could be part of the problem. You're not expected to restart a service in such a short time.
M Mike1970 Well-Known Member Licensed User Longtime User Oct 19, 2019 #19 udg said: This could be part of the problem. You're not expected to restart a service in such a short time. Click to expand... mm ok, i try to increase the time Upvote 0
udg said: This could be part of the problem. You're not expected to restart a service in such a short time. Click to expand... mm ok, i try to increase the time
M Mike1970 Well-Known Member Licensed User Longtime User Oct 19, 2019 #20 udg said: This could be part of the problem. You're not expected to restart a service in such a short time. Click to expand... 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) Upvote 0
udg said: This could be part of the problem. You're not expected to restart a service in such a short time. Click to expand... 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)