Search code examples
androidsql-updatecloud

Is there a way to make my app constantly look for connection in the background?


I'm trying to figure out if it is plusible to make an app constantly look for any kind of internet connection so once it finds any it makes a comparison of its local database with the one in the cloud and upload anything that is not in the cloud.

I was thinking about a code that triggers every time the phone connects to the internet but my research turned to be inconclusive and I'm running out of time.


Solution

  • You wouldn't do it that way. There's methods of being notified when an internet connection is made in Android, but you really wouldn't even do that. Instead you'd use WorkManager to schedule a job that requires internet, and let it launch the job at an appropriate time for you. See https://developer.android.com/topic/libraries/architecture/workmanager