Using An Alarmmanager To Check Periodically That My Permanent Service Is Running
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 can
Solution 1:
You could look at setting up a broadcastreceiver on any number of device broadcasts like wifi connection state and boot;
<receiverandroid:name=".receivers.BootReceiver" ><intent-filter><actionandroid:name="android.intent.action.BOOT_COMPLETED" /></intent-filter></receiver><receiverandroid:name=".receivers.WifiReceiver"><intent-filter><actionandroid:name="android.net.wifi.STATE_CHANGE" /></intent-filter></receiver>
Solution 2:
Set your service as a foreground service (see this). Android will only kill this service in extreme situations. You can still use the alarm manager as a "safety net" to restart the service if it accidentally crashes. This is the best you can do. Nothing is 100%.
Post a Comment for "Using An Alarmmanager To Check Periodically That My Permanent Service Is Running"