I have noticed that no one mentioned WorkManger
solution which is better and support most of android devices.
You should have a Worker
with network constraint AND it will fired only if network available, i.e:
val constraints = Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()
val worker = OneTimeWorkRequestBuilder<MyWorker>().setConstraints(constraints).build()
And in worker you do whatever you want once connection back, you may fire the worker periodically .
i.e:
inside dowork()
callback:
notifierLiveData.postValue(info)