I am developing an Android App for Android 5 (it's only for a specific device) and I need to monitor network connectivity. I would like to see it work this way:
- The application starts and checks whether there is a connection and what is its type.
- The Internet connection is checked every X seconds (e.g 3 seconds) or only changes are detected.
My question is: what is the best way to do it? JobScheduler, AlarmManager or it can be done only with BroadcastReceiver (with CONNECTIVITY_ACTION)?
I tried with JobScheduler with setPeriodic function, but it doesn't start immediately as I wanted. And I read that in higher version of Android the minimum period is 15 minutes. BroadcastReceiver with CONNECTIVITY_ACTION seems to break the connection after several minutes.