Using Job Scheduler in Android API <21

后端 未结 7 1941
臣服心动
臣服心动 2020-12-13 06:27

I was looking at a scheduling tutorial by Vogella. It mentions the Job Scheduler API that was introduced in API 21 of Android. My question is can it be implemented i

相关标签:
7条回答
  • 2020-12-13 06:38

    from now on (after I/O 2015), you can also use new GcmNetworkManager. How to use it and how it works is described here - https://developers.google.com/cloud-messaging/network-manager

    It does a lot cool stuff like it persists your tasks trough reboots. On Lolipop it uses JobScheduler, on pre-Lolipop it uses it's own implementation.

    EDIT:

    An example code on how to use it : https://github.com/jacktech24/gcmnetworkmanager-android-example

    0 讨论(0)
  • 2020-12-13 06:38

    The recommended approach for pre-lollipop devices is to use the https://github.com/firebase/firebase-jobdispatcher-android#user-content-firebase-jobdispatcher-

    Read more on https://developer.android.com/topic/performance/scheduling.html#fjd

    Firebase JobDispatcher is an open-source library that provides an API similar to JobScheduler in the Android platform. Firebase JobDispatcher serves as a JobScheduler-compatibility layer for apps targeting versions of Android lower than 5.0 (API level 21).

    Firebase JobDispatcher supports the use of Google Play services as an implementation for dispatching (running) jobs, but the library also allows you to define and use other implementations: For example, you might decide to use JobScheduler or write your own, custom code. Because of this versatility, we recommend that you use this Firebase JobDispatcher if your app targets a version of Android lower than 5.0 (API level 21).

    For more information about Firebase JobDispatcher, refer to its documentation and source code.

    0 讨论(0)
  • 2020-12-13 06:38

    According to the latest background job scheduling APIs, you should use WorkManager.

    WorkManager allows you to schedule background tasks that need guaranteed completion (regardless of whether the app process is around or not). WorkManager provides JobScheduler-like capabilities to API 14+ devices, even those without Google Play Services.

    WorkManager is queryable (observable), has strong support for graphs of work, and a fluent API.

    If you are using JobScheduler, FireBaseJobScheduler, and/or AlarmManager plus BroadcastReceivers, you should consider using WorkManager instead. To learn more, see Work Manager.

    0 讨论(0)
  • 2020-12-13 06:42

    There is a very nice and powerful job scheduler library from Evernote. It uses the best method on each SDK level and gives you one very clean and elegant interface to schedule and run jobs.

    0 讨论(0)
  • 2020-12-13 06:55

    Refer this link about Android N Preview API Overview.

    GCMNetworkManager, part of Google Play Services, which offers similar job scheduling with compatibility across legacy versions of Android.

    0 讨论(0)
  • 2020-12-13 06:57

    There are a few methods of running "jobs" pre-lollipop.

    As mentioned you can use the JobSchedulerCompat library, but this library has a huge difference compared to the default Lollipop API:

    On Lollipop jobs are batched and scheduled for all apps at once. The library however does not have access to other apps data and therefore can't combine jobs from two different apps using the library.

    Another option you might want to try is the AlarmManager API. This API can be used for scheduling jobs, but the one difference is that the AlarmManager does not have constraints other than timing for running jobs.

    Since KitKat the AlarmManager API also batches jobs when not scheduled with the "exact" methods. Before KitKat jobs are not batched.

    If your goal is to sync data, than the Sync-Adapter API might be useful: Sync-Adapter

    References: AlarmManager, JobSchedulerCompat

    0 讨论(0)
提交回复
热议问题