{"id":13778425,"url":"https://github.com/googlearchive/firebase-jobdispatcher-android","last_synced_at":"2025-09-27T08:30:54.530Z","repository":{"id":146872504,"uuid":"59078087","full_name":"googlearchive/firebase-jobdispatcher-android","owner":"googlearchive","description":"DEPRECATED please see the README.md below for details.","archived":true,"fork":false,"pushed_at":"2020-04-07T21:08:39.000Z","size":573,"stargazers_count":1789,"open_issues_count":0,"forks_count":211,"subscribers_count":139,"default_branch":"master","last_synced_at":"2024-04-14T12:03:15.585Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/googlearchive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-05-18T03:15:58.000Z","updated_at":"2024-03-12T12:40:37.000Z","dependencies_parsed_at":"2024-01-15T08:06:51.694Z","dependency_job_id":null,"html_url":"https://github.com/googlearchive/firebase-jobdispatcher-android","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googlearchive%2Ffirebase-jobdispatcher-android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googlearchive%2Ffirebase-jobdispatcher-android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googlearchive%2Ffirebase-jobdispatcher-android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googlearchive%2Ffirebase-jobdispatcher-android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/googlearchive","download_url":"https://codeload.github.com/googlearchive/firebase-jobdispatcher-android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234410658,"owners_count":18828262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:00:53.735Z","updated_at":"2025-09-27T08:30:54.069Z","avatar_url":"https://github.com/googlearchive.png","language":"Java","funding_links":[],"categories":["Helpers","任务调度"],"sub_categories":[],"readme":"# Firebase JobDispatcher\n\n[ci-badge]: https://travis-ci.org/firebase/firebase-jobdispatcher-android.svg?branch=master\n[ci-link]: https://travis-ci.org/firebase/firebase-jobdispatcher-android\n\n## Status: Archived\nThis repository has been archived and is no longer maintained.\n\n![status: inactive](https://img.shields.io/badge/status-inactive-red.svg)\n\n---\n\n## Update: April 2019\n\n**Last year, we announced Android Jetpack\n[WorkManager](https://developer.android.com/topic/libraries/architecture/workmanager/).\nWorkManager, the new job management system in Jetpack, incorporates the features\nof Firebase Job Dispatcher (FJD) and Android’s\n[JobScheduler](https://developer.android.com/reference/android/app/job/JobScheduler)\nto provide a consistent job scheduling service back to api level 14 while\nleveraging JobScheduler on newer devices. WorkManager works with or without\nGoogle Play Services, which is something FJD cannot do. WorkManager was first\nreleased to alpha in May 2018 and then went thru extensive iteration and\nimprovement based on developer feedback including 10 alphas; it moved to beta on\nDec 19, 2018, and was released to\n[stable](https://developer.android.com/jetpack/androidx/releases/work#1.0.0) on\nMar 5, 2019. One thing the team has been discussing at some length is whether it\nwould be better for developers in the long run if we create one holistic\nsolution via WorkManager; where we can pool all of our efforts and also give\ndevelopers a single unified recommended path?**\n\n**After careful evaluation, the team has decided to focus all of our efforts on\nWorkManager and to deprecate Firebase Job Dispatcher. We have modified our plans\nin direct response to developer feedback in order to make this as easy for you\nas possible. We know that managing background work is a critical part of your\napp and these changes impact you. We want to support you through this migration\nas much as we can by giving you as much advance notice as possible to make these\nchanges. Firebase Job Dispatcher will be archived in github in about 1 year, on\nApr 7, 2020. Apps should migrate to WorkManager or an alternative job management\nsystem before this date.**\n\n**We’ve created a detailed\n[migration guide](https://developer.android.com/topic/libraries/architecture/workmanager/migrating-fb)\nto assist you in the transition to WorkManager. After Apr 7, 2020, this github\nrepository will be archived and support for FJD customer issues will stop.\nAdditionally, FJD will stop working once your app starts targeting an Android\nversion after Android Q.**\n\n**We are continuing to invest in and add new features to WorkManager and welcome\nany feedback or feature\n[requests](https://issuetracker.google.com/issues/new?component=409906\u0026template=1094197).**\n\nThe Firebase JobDispatcher is a library for scheduling background jobs in your\nAndroid app. It provides a [JobScheduler][]-compatible API that works on all\nrecent versions of Android (API level 14+) that have Google Play services\ninstalled.\n\n## Overview\n\n### What's a [JobScheduler][]?\n\nThe JobScheduler is an Android system service available on API levels 21\n(Lollipop)+. It provides an API for scheduling units of work (represented by\n[`JobService`][JobService] subclasses) that will be executed in your app's\nprocess.\n\n### Why is this better than background services and listening for system broadcasts?\n\nRunning apps in the background is expensive, which is especially harmful when\nthey're not actively doing work that's important to the user. That problem is\nmultiplied when those background services are listening for frequently sent\nbroadcasts (`android.net.conn.CONNECTIVITY_CHANGE` and\n`android.hardware.action.NEW_PICTURE` are common examples). Even worse, there's\nno way of specifying prerequisites for these broadcasts. Listening for\n`CONNECTIVITY_CHANGE` broadcasts does not guarantee that the device has an\nactive network connection, only that the connection was recently changed.\n\nIn recognition of these issues, the Android framework team created the\n[JobScheduler][]. This provides developers a simple way of specifying runtime\nconstraints on their jobs. Available constraints include\n[network type][js-network-type], [charging state][js-charging-state], and\n[idle state][js-idle-state].\n\nThis library uses the scheduling engine inside\n[Google Play services](formerly the [GCM Network Manager][nts] component) to\nprovide a backwards compatible (back to Gingerbread) [JobScheduler][]-like API.\n\nThis I/O presentation has more information on why background services can be\nharmful and what you can do about them:\n\n[![Android battery and memory optimizations][io-video-img]][io-video-link]\n\nThere's more information on upcoming changes to Android's approach to background\nservices on the [Android developer preview page][n-preview-bg-optimizations].\n\n[n-preview-bg-optimizations]: https://developer.android.com/preview/features/background-optimization.html\n[io-video-img]: http://img.youtube.com/vi/VC2Hlb22mZM/hqdefault.jpg\n[io-video-link]: https://youtu.be/VC2Hlb22mZM\n[js-network-type]: https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setRequiredNetworkType(int)\n[js-charging-state]: https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setRequiresCharging(boolean)\n[js-idle-state]: https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setRequiresDeviceIdle(boolean)\n\n### Requirements\n\nThe FirebaseJobDispatcher currently relies on the scheduling component in Google\nPlay services. Because of that, it won't work on environments without Google\nPlay services installed.\n\n### Comparison to other libraries\n\nLibrary                                     | Minimum API | Requires Google Play   | Service API\u003csup\u003e[1](#fn1)\u003c/sup\u003e | Custom retry strategies\n------------------------------------------- | ----------- | ---------------------- | ------------------------------- | -----------------------\nFramework [JobScheduler][]                  | 21          | No                     | JobScheduler                    | Yes\nFirebase JobDispatcher                      | 14          | Yes                    | JobScheduler                    | Yes\n[evernote/android-job][]                    | 14          | No\u003csup\u003e[2](#fn2)\u003c/sup\u003e | Custom                          | Yes\nAndroid [WorkManager][]\u003csup\u003e[3](#fn3)\u003c/sup\u003e | 14          | No\u003csup\u003e[2](#fn2)\u003c/sup\u003e | Custom                          | Yes\n\n\u003csup\u003e\u003ca name=\"fn1\"\u003e1\u003c/a\u003e\u003c/sup\u003e Refers to the methods that need to be implemented in the\nService subclass.\u003cbr\u003e\n\u003csup\u003e\u003ca name=\"fn2\"\u003e2\u003c/a\u003e\u003c/sup\u003e Uses AlarmManager or JobScheduler to support API levels \u003c= 21 if Google\nPlay services is unavailable.\u003cbr\u003e\n\u003csup\u003e\u003ca name=\"fn3\"\u003e3\u003c/a\u003e\u003c/sup\u003e Currently in alpha phase, soon to graduate to beta.\u003c/br\u003e\n\n## Getting started\n\n### Installation\n\nAdd the following to your `build.gradle`'s dependencies section:\n\n```groovy\nimplementation 'com.firebase:firebase-jobdispatcher:0.8.6'\n```\n\n### Usage\n\n#### Writing a new JobService\n\nThe simplest possible `JobService`:\n\n```java\nimport com.firebase.jobdispatcher.JobParameters;\nimport com.firebase.jobdispatcher.JobService;\n\npublic class MyJobService extends JobService {\n    @Override\n    public boolean onStartJob(JobParameters job) {\n        // Do some work here\n\n        return false; // Answers the question: \"Is there still work going on?\"\n    }\n\n    @Override\n    public boolean onStopJob(JobParameters job) {\n        return false; // Answers the question: \"Should this job be retried?\"\n    }\n}\n```\n\n#### Adding it to the manifest\n\n```xml\n\u003cservice\n    android:exported=\"false\"\n    android:name=\".MyJobService\"\u003e\n    \u003cintent-filter\u003e\n        \u003caction android:name=\"com.firebase.jobdispatcher.ACTION_EXECUTE\"/\u003e\n    \u003c/intent-filter\u003e\n\u003c/service\u003e\n```\n\n#### Creating a Dispatcher\n\n```java\n// Create a new dispatcher using the Google Play driver.\nFirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context));\n```\n\n#### Scheduling a simple job\n\n```java\nJob myJob = dispatcher.newJobBuilder()\n    .setService(MyJobService.class) // the JobService that will be called\n    .setTag(\"my-unique-tag\")        // uniquely identifies the job\n    .build();\n\ndispatcher.mustSchedule(myJob);\n```\n\n#### Scheduling a more complex job\n\n```java\nBundle myExtrasBundle = new Bundle();\nmyExtrasBundle.putString(\"some_key\", \"some_value\");\n\nJob myJob = dispatcher.newJobBuilder()\n    // the JobService that will be called\n    .setService(MyJobService.class)\n    // uniquely identifies the job\n    .setTag(\"my-unique-tag\")\n    // one-off job\n    .setRecurring(false)\n    // don't persist past a device reboot\n    .setLifetime(Lifetime.UNTIL_NEXT_BOOT)\n    // start between 0 and 60 seconds from now\n    .setTrigger(Trigger.executionWindow(0, 60))\n    // don't overwrite an existing job with the same tag\n    .setReplaceCurrent(false)\n    // retry with exponential backoff\n    .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL)\n    // constraints that need to be satisfied for the job to run\n    .setConstraints(\n        // only run on an unmetered network\n        Constraint.ON_UNMETERED_NETWORK,\n        // only run when the device is charging\n        Constraint.DEVICE_CHARGING\n    )\n    .setExtras(myExtrasBundle)\n    .build();\n\ndispatcher.mustSchedule(myJob);\n```\n\n#### Cancelling a job\n\n```java\ndispatcher.cancel(\"my-unique-tag\");\n```\n\n#### Cancelling all jobs\n\n```java\ndispatcher.cancelAll();\n```\n\n\u003c!--\n## Next steps\n\n- Browse the [API documentation][]\n\n[API documentation]: TODO: put link here\n\n--\u003e\n\n## Contributing\n\nSee the [CONTRIBUTING.md](CONTRIBUTING.md) file.\n\n## Support\n\nThis library is actively supported by Google engineers. If you encounter any\nproblems, please create an issue in our [tracker][].\n\n## License\n\nApache, see the [LICENSE](LICENSE) file.\n\n[tracker]: https://github.com/firebase/firebase-jobdispatcher-android/issues\n[nts]: https://developers.google.com/cloud-messaging/network-manager\n[fcm]: https://firebase.google.com/docs/cloud-messaging/\n[gcm]: https://developers.google.com/cloud-messaging/\n[JobService]: https://developer.android.com/reference/android/app/job/JobService.html\n[JobScheduler]: https://developer.android.com/reference/android/app/job/JobScheduler.html\n[Google Play services]: https://developers.google.com/android/guides/overview\n[evernote/android-job]: https://github.com/evernote/android-job\n[WorkManager]: https://developer.android.com/topic/libraries/architecture/workmanager/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgooglearchive%2Ffirebase-jobdispatcher-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgooglearchive%2Ffirebase-jobdispatcher-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgooglearchive%2Ffirebase-jobdispatcher-android/lists"}