Android provides three different APIs to run tasks in the future. All of them have their benefits and downsides. The AlarmManager’s API has changed over time, so you need to be careful which method you use on which platform. The JobScheduler is only available on Android Lollipop and Marshmallow, whereas the GcmNetworkManager is only available on devices with Google Play preinstalled.
There are three options with changing API levels, so it can be hard to know which one you need. You will also end up with many different paths in your code all doing the same for a different environment. Today, we’re open-sourcing a unified library to schedule jobs on Android. Depending on your requirements, this library decides which API suits your job. It provides a superset of all features from the existing AlarmManager, JobScheduler and GcmNetworkManager, e.g. you can run your job only if the device has a working Internet connection and is charging.
Setting up the library is straightforward. You only need to initialize the JobManager and then you can start scheduling your jobs. You don’t need to declare any services, receivers or permissions in your manifest. The project page on GitHub has you covered with detailed instructions and code samples.
We’re excited to get your feedback, feature recommendations, bug reports and pull requests. Happy coding!