I have a tracking app that needs to send location updates to a web server every 5 seconds. This works fine as long as the app is awake/visible.
If the device is locked the app is put to sleep after 15 minutes (give or take a second or two).
Adding the app to the "Unmonitored apps" under Battery app power monitor doesn't stop it getting put to sleep either.
I have tried creating a wakelock, ie
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TrackerTag");
wakeLock.acquire();
but even that does not help. The app still goes to sleep and stops sending updates. I do not need to keep the screen on (hence the PARTIAL_WAKE_LOCK) but I do need the app to stay awake so it can feed GPS coordinates to a server database.
I have added the app to the ignore list for battery optimization list so it isn't that killing it and the above wakelock seems to do nothing.
I also tried creating the service as a foreground service ie Android - implementing startForeground for a service? and that also does not save the app being put to sleep after 15 minutes.
What do I need to do to tell android "leave this app alone no matter what and do not stop it unless I specifically close all and kill it"?