Android Question Continous background GPS tracking

Mike1970

Well-Known Member
Licensed User
Longtime User
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:

OliverA

Expert
Licensed User
Longtime User
Nothing, after 11 hours the process was killed even if i scheduled it every 30 minutes!
Which may be normal. Have you happen to read this: https://www.b4x.com/android/forum/threads/”hey-android-vendors-don’t-kill-my-app-”.101495/#content?
Android 6.0
The newer the version, the more aggressive Android can be in killing your app
before the update
What update?
My phone: Meizu m5c
Have you ever thought it is the phone that is the issue? A quick google on the manufacturer shows that they have broken things in the past with updates.

The following just happened to me last week: An app I wrote did not work on one phone. The app runs on Lollipop and up. Tested on 5,7,8 and 9. On a new phone with version 6 it started acting up. Come to find out, the Android on that phone has the following missing: android.content.res.XResources. This should be readily available on Android, but not on this phone. Why? No clue, just a guess: Since it has a tiny screen, the phone manufacturer decided to save resources by excluding that part of Android. Also, while researching this issue I discovered that some missing parts may indicate the Carrier of a phone (I saw a code fragment that did a try catch on a system call, with the catch being that if the class is missing, it's a Verizon phone - mind blowing!).

So, what now? One approach I have that may/may not work for you is the usage of a watchdog app. With a watchdog app, you can determine if the first app is running, and if it is not, restart it. Actually, the way I approach it is that the main application calls an intent of the watchdog app. If the Watchdog happens to not be running, the intent will start it. The Watchdog keeps track of the intents. If over a period of time it does not receive any intents from the main application, it will call an intent of the main application, therefore starting it. So far, this has worked very well. As to what it took to write this, this forum and some searching on the internet provided everything. It took me awhile to get it correct and to understand intents and the entries needed in the Manifest but figuring that out was part of the fun.

but the other apps are still running after 6+ hours at this point
If those are popular apps or apps that come with the phone preinstalled, that would make perfect sense (since it would make no sense for a device manufacturer to kill popular apps/its own apps).
 
Upvote 0

arnold steger

Member
Licensed User
Longtime User
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
Every time when start the service then activated the sound notification on Android 9.
after notification.Initialize2... i have insert
notification.Sound=False

how can stopped sound notification?
 
Upvote 0
Top