I have one service on my Android App, this service posts in my server every 20 seconds when the session of user in my App is active.
This runs ok during several days if my device is connected to power, but if the device is disconnected and is unused (with the screen off) the service seems to stop but few minutes later begin to run again and continues to run for hours.
In the service, I use wakelock to avoid the device from going to sleep mode.
I apologize for my English so basic