I have a Service
which should keep a permanent connection to a server in order to receive notifications. It's critical for my app to get the messages from the server on time.
I cannot use GCM Push because the connection will be in the local network and the phone may not have any internet connection. I also know about the battery issues of keeping a permanent connection within a service, but I will let the user choose this option and inform him/her about the potential battery drain (Actually the feature makes mainly sense when the device is always in the same place connected to power). I also know that the Android system can kill my Service anytime, or even the user can use a task killer to get rid of all the services running at the time.
Said that, I thought about using an AlarmManager
periodically to check whether my Service
is running and restarting it in case it is not. I'm not convinced with this option, since the server can send a message after the service was killed but not yet restarted by the AlarmManager
.
My question is basically whether there are better strategies to ensure that I get the messages on time?
So far all the related info I could find stand for avoiding the permanent service and use something else, but I have no other option because of the nature of my use case.