You do not need to monitor network connectivity at all times for this use case. When the user is using your app, then you can check network as per the link you provided. If you are not connected, you can use the JobScheduler
to schedule a job and use jobInfoBuilder.setRequiredNetworkType(NETWORK_TYPE_ANY)
, and the system will run your job when there is network connectivity even if your app has since gone to the background. The job should simply start up a Service that uploads whatever changes are pending.
Alternatively, if it fits your use case, you can write a SyncAdapter
and simply request a sync, and the system's SyncManager
will run your SyncAdapter
when appropriate.