Compatible version of Android JobScheduler - alternative [closed]

谁都会走 提交于 2019-12-08 14:47:11

问题


Is there a library or at least some open source example that provides functionality of new Android-L JobScheduler API. It is not to hard to implement my own version (with very limited functionality) but on the other hand it is not trivial either.

So to sum it up is there anything that at least can provide subset of functions of new JobScheduler API ?


回答1:


A backport of Android Lollipop's JobScheduler to api 10+ https://github.com/evant/JobSchedulerCompat




回答2:


Just use GCM Network Manager. It provides APIs to schedule tasks. It is available on pre API level 21 devices. On API level 21+ devices it uses Job Scheduler internally.




回答3:


You can do some of it yourself, but unfortunately an app cannot itself achieve comparable functionality to a lot of the job scheduler API. The problem is that monitoring several of the execution criteria that the job scheduler provides (notably charging state, device idleness, and connectivity) would require that your app be running constantly just to receive the broadcasts about those states -- and the performance cost of running constantly will outweigh the other benefits even if your app is the only one doing it. If every app is trying to run continuously to do the same kind of monitoring, the user's experience is going to be terrible.

The closest you can come in a reasonable way by yourself is to run a service "occasionally" to check the constraints you're interested in, and back off and retry later if they don't hold at the time you check. You need to be careful about how you're scheduling things, too -- in particular, if you're going to be using the network you need to be extremely careful that you are not accidentally causing lots of devices to hit the network at the same time. Cell carriers get very unhappy if they see simultaneous traffic from your app from every device on their network. Also, remember to avoid exact alarms if at all possible, so that the OS has leeway to batch your app's work together with others'.

Device-idle / user activity is hard for your app to track by itself, unfortunately, but connectivity and charge state are readily available.

A final tool at your disposal is the Sync Manager, which requires more infrastructure to use but does offer some reasonably powerful scheduling facilities, especially around connectivity requirements.




回答4:


As of November 2015, this library https://github.com/evant/JobSchedulerCompat mentions that it is not maintained actively

Warning this project is not maintained!

Here is a library called Trigger https://github.com/airk000/Trigger which also claims to be a backport of JobScheduler service and has the following features as per its documentation.

  1. support multi conditions combination with one job
  2. inner conditions: device charging, unmeterred network and idle status
  3. support persist job, means that persist-able job can be triggered after device reboot
  4. support job's deadline, last chance to be triggered
  5. allow your job's action runs in background or main thread, follow your configuration


来源:https://stackoverflow.com/questions/25203254/compatible-version-of-android-jobscheduler-alternative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!