I am developing an app in which I want to detect network state in my app and do some task accordingly , for this I am using broadcast receiver, which is working fine but when I inspect code this will gives me suggestion to replace with Job scheduler, I want to know how do I do. and also Is job scheduler works below API 11.
Asked
Active
Viewed 2,437 times
2
-
Check [this](http://stackoverflow.com/questions/26441505/android-5-0-jobscheduler-api-on-earlier-versions) and also [this](http://stackoverflow.com/questions/37217283/detect-network-state-change-using-jobschedulers-in-android) , these might help you solve your issue. – Jaydroid Sep 28 '16 at 10:13
1 Answers
0
JosScheduler is available from API 21(Lollipop) only. The framework will be intelligent about when you receive your callbacks, and attempt to batch and defer them as much as possible. A useful tutorial could be find here https://code.tutsplus.com/tutorials/using-the-jobscheduler-api-on-android-lollipop--cms-23562

Febi M Felix
- 2,799
- 1
- 10
- 13
-
This sucks. If I have a network thread and want to stop it when there's no connectivity how do I do that? I don;t want to manually check if there's connectivity or not. The previous way would tell you _either_ _or_ – TheRealChx101 Mar 22 '19 at 02:58
-
A stable version of WorkManager is available now. Please check this link for details. https://developer.android.com/topic/libraries/architecture/workmanager . This new architecture component helps in doing scheduled tasks. – Febi M Felix Mar 22 '19 at 10:38
-
It only has one option: Running when there's a connection. I want to run when a connection is lost so I can stop a thread and kick its loop out of spin. I have network thread that will keep running until it connects to the server. Currently I'm using a timed `ojbect.wait` but it depletes the battery like crazy. Basically I want to get notified of network changes, then I'll check if a connection is possible otherwise quit. That's all – TheRealChx101 Mar 23 '19 at 05:57
-
I just used scheduled tasks (`Handler`) instead of relying on network events. I have a foreground service which holds the handler and after some user-configured time, it will spawn the connection thread. If the connection thread fails to connect, it will reschedule another task for another connection attempt. It's easier and simpler that way I guess. – TheRealChx101 Mar 24 '19 at 21:59