I have an application where the user is requested to sign in and then presented with an activity. A service is also started on the sign in which uses the location manager to track his current location. everything works perfectly until the application is left in standby mode (screen off an app in background for more than ~ 1 hour)
how can I prevent this?
as I understand, if I have a foreground service running, the OS should not kill the app.. so what am I doing wrong? the OS I am testing on is Oreo
starting the service on sign in:
startService(intent);
the service:
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
@Override
public void onCreate() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Notification notification = updateNotificationContent(); // the service notification
if (notification == null)
stopSelf();
startForeground(id, notification);
}
I added logging on destroy the function of the activity and service to detect when this is happening but the log is never written when this behavior happens (of course it enters in normal case when I destroy the app)