I am developing internal Android apps for the company I work for. In various places in the apps I need to connect to an internal server. This server is shutdown for maintenance for a period of time every night so there are times when it is not available. There may also be times when the wi-fi connection on the tablet drops.
If a tablet can't connect to the server (either due to wi-fi being down or because the server is down) I want the app to work in an offline mode - basically displaying data from the local database rather than getting live data from the server database. Also any data to be uploaded to the server should be queued until back online.
I am considering having a background service that runs a check every X seconds to see if the wi-fi is connected and if so, check if the server is available (via an HTTP HEAD request). It would then send out a broadcast to say if online or offline and other apps could receive this broadcast and save the connection status. Then whenever there is any activity in the apps requiring access to the server, they can check the status first and decide how to behave.
The downside to this is that the service would constantly be running in the background and could cause performance issues / battery drainage, although having done a little testing I haven't seen any evidence of this yet so I don't know whether it would actually ever be a problem.
So what I'm wondering is whether this method is a good idea or not and if there is a better way to check whether online or offline.