Reputation: 2156
I have a service that is running as a foreground service
startForeground(1234, notification);
In this service I have a runnable that should run every 15 minutes :
private Runnable runnable = new Runnable()
{
@Override
public void run()
{
Log.d("maw", "Gps::run");
if (Constants.checkInternet(getApplicationContext())) checkSheet();
handler.postDelayed(this, Constants.REFRESH_TIME);
}
};
When the device is connected to the internt it executes the method checkSheet(). This method checks some stuff with a server, and depending on the result it starts up the GPS and track the location of the device.
locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_TIME, GPS_DISTANCE, this);
Now... In our tests this all seems working fine. But the users have problems, in that sometimes they only see the trace hours after it should have started logging.
Now the question is what the reason is behind this. I am guessing they don't use their devices as much as our devices and the devices are going into a sleeping mode our test devices never enter because we use the devices more frequently
Some questions : For a foreground service : - Does the Runnable stop running every 15 minutes when the device goes to some deeper sleep mode ? - Is it not possible to initialize a locationManager.requestLocationUpdates when the device is in some deeper sleep mode ?
Upvotes: 0
Views: 1344
Reputation: 2156
After a lot of testing it seemed that the runnable sometimes crashed and completely stopped working.
After fixing that issue now it seems that for a foreground service the Runnable does keep running, and the locationManager.requestLocationUpdates does do what it should do.
Upvotes: 0
Reputation: 51
Try to use AlarmManager, so your service only needs to be in memory when it is actually doing work. Or you can use wakelock.
Upvotes: 1