asynchronously, outside the direct flow of user interaction. Some examples of these asynchronous tasks are: • Updating network resources. • Downloading information. • Updating background tasks. • Scheduling system service calls. Scheduling this work intelligently can improve your app’s performance, along with aspects of system health such as battery life.
several scheduling APIs for jobs that need to be scheduled outside the scope of an application’s lifecycle. Most of these come along with features that improve battery life & optimise resource utilisation. • Currently available APIs: ◦ Handler ◦ AlarmManager ◦ JobScheduler ◦ GcmNetworkManager
a delay or repeat them periodically on a given thread. • This is achieved by constructing a Handler and then “posting” runnable code to the event message queue on the thread to be processed. + Preferred for normal timing operations (ticks, timeouts, etc) + Suitable where scheduling needs to happen with an interval < 30 second − Doesn’t work efficiently while the app is in the background or not running at the moment.
to run even when the app is not in the foreground. • It leverages the alarm service on the phone to cause periodic executions of a service which will run continuously until explicitly stopped. + Available on all devices and all OS versions + Easier to send a Broadcast to start a service delayed using this API − There have been numerous changes with changing Android API Versions − Periodic Alarms only work in case the interval b/w consecutive occurrences is > 60sec − Alarms get reset on device reboot and hence need to be explicitly re-initiated
an efficient way. • Jobs are scheduled based on specified criteria, such as device is charging, idle, connected to a network, or connected to an unmetered network. They are queued up in the system to be performed later when these criteria are met. • Along with this, Android also tries to batch these jobs together to optimize resources. + Relatively easier to use & provides customizations for the developer to schedule jobs better + Respects device state and prevents exploitation of resources by apps − Only available on Android Lollipop and above (21+) − Jobs with network dependency don’t get scheduled if the periodic interval < ~30 seconds − Jobs stop getting scheduled in Power-Saver Mode if network connectivity is a dependency
saving features from JobScheduler, but with backward compatibility and simplicity of its Service counterpart. • Uses JobScheduler APIs behind the scenes for API level 21+, and features support for previous Android versions using Google Play Services. + Supported on Android Gingerbread and above (9+) − Google Play Services is a prerequisite − Jobs with network dependency don’t get scheduled if the periodic interval < ~30 secs. − Jobs stop getting scheduled in Power-Saver Mode if network connectivity is a dependency
types of jobs for interval ranging from 1sec to anything near 24 hours. − Network dependent (or independent) jobs − Periodic (or Nonperiodic) jobs Thus we needed a simpler & reliable API to schedule jobs on all devices and in all conditions.
suitable API (for all devices or Android versions) • Inflexibility of switching between APIs • Amount of boilerplate code required for setting up • API changes with varying Android API versions • APIs not being backward compatible This is when we built Smart Scheduler, an open-source scheduling library, which takes care of Scheduling APIs, their boilerplate code and nuances associated with each API.