A presentation on how and when to use a WorkManager in Android. This presentation gives deep insight into what type of background service we can use in the background.
We delve deep into working and functionalities provided by WorkManger and see how we can add One-Time and Periodic tasks along with various constraints we can set to initialization of a worker.
The document discusses using queue systems to execute tasks asynchronously in the background to improve application performance and scalability. It provides an overview of different types of queue systems including dedicated job queues like Gearman and Beanstalkd, message queues like RabbitMQ, and software-as-a-service queues like Amazon SQS. It also discusses using databases like Redis as queues. The document then dives deeper into examples of using Gearman and Beanstalkd in PHP applications and compares their performance. It also discusses using queue abstraction layers and best practices for queueing jobs.
Gearman is a software framework that allows distributing work across multiple machines. It consists of a daemon, clients, and workers. The daemon handles communication between clients and workers. Clients submit work to the daemon, which passes it to workers to complete. Workers register functions they can perform and handle tasks asynchronously. Gearman provides load balancing and allows processing work in parallel across languages. It can improve performance for tasks like image processing, email sending, and log analysis.
The document discusses the importance of performance and load testing web applications. It defines performance as how fast, robust, and resource-effective a system is. Load testing involves stressing an application with simulated user load to determine its capacity and stability under heavy usage. The document outlines best practices for load testing methodology, tooling, and interpreting results to optimize performance. It promotes using an asynchronous, non-blocking tool like Gatling for efficient, maintainable load testing that provides meaningful reports.
Performance tests with Gatling are difficult for three main reasons:
1) The test environment must closely simulate production in terms of hardware, software, and load.
2) Proper infrastructure for monitoring, logging, and isolating tests is required.
3) Performance intuition can be wrong, so statistics like percentiles must be used rather than averages.
Gearman is an open-source application framework that allows for the distribution of work across multiple machines. It uses a queueing system to dispatch jobs to workers to be processed asynchronously. Clients submit jobs to the Gearman server which handles distributing jobs to available worker processes to execute the requested tasks. This allows for scalable and fault-tolerant processing of jobs in parallel across a pool of machines.
Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. In other words, it is the nervous system for how distributed processing communicates.
The document discusses using queue systems to execute tasks asynchronously in the background to improve application performance and scalability. It provides an overview of different types of queue systems including dedicated job queues like Gearman and Beanstalkd, message queues like RabbitMQ, and software-as-a-service queues like Amazon SQS. It also discusses using databases like Redis as queues. The document then dives deeper into examples of using Gearman and Beanstalkd in PHP applications and compares their performance. It also discusses using queue abstraction layers and best practices for queueing jobs.
Gearman is a software framework that allows distributing work across multiple machines. It consists of a daemon, clients, and workers. The daemon handles communication between clients and workers. Clients submit work to the daemon, which passes it to workers to complete. Workers register functions they can perform and handle tasks asynchronously. Gearman provides load balancing and allows processing work in parallel across languages. It can improve performance for tasks like image processing, email sending, and log analysis.
The document discusses the importance of performance and load testing web applications. It defines performance as how fast, robust, and resource-effective a system is. Load testing involves stressing an application with simulated user load to determine its capacity and stability under heavy usage. The document outlines best practices for load testing methodology, tooling, and interpreting results to optimize performance. It promotes using an asynchronous, non-blocking tool like Gatling for efficient, maintainable load testing that provides meaningful reports.
Performance tests with Gatling are difficult for three main reasons:
1) The test environment must closely simulate production in terms of hardware, software, and load.
2) Proper infrastructure for monitoring, logging, and isolating tests is required.
3) Performance intuition can be wrong, so statistics like percentiles must be used rather than averages.
Gearman is an open-source application framework that allows for the distribution of work across multiple machines. It uses a queueing system to dispatch jobs to workers to be processed asynchronously. Clients submit jobs to the Gearman server which handles distributing jobs to available worker processes to execute the requested tasks. This allows for scalable and fault-tolerant processing of jobs in parallel across a pool of machines.
Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. In other words, it is the nervous system for how distributed processing communicates.
This document discusses different approaches for handling threading in Android apps, including AsyncTask for quick background work, IntentService for work that should continue after the user leaves the app, and WakefulIntentService for long-running work that requires keeping the device awake. It recommends using AsyncTask and retained fragments for work taking 1-15 seconds, IntentService and an event bus for 1-15 seconds, and WakefulIntentService and an event bus for work lasting 15+ seconds. All approaches require dealing with thread safety and have limitations like inability to directly update the UI. Sample code is provided.
This document provides a script to speed up the creation or rebuilding of large indexes in an Oracle database. The script optimizes index creation through several techniques: setting parameters to increase direct I/O size, sort area size, parallel execution degree, and enabling nologging mode. It also recommends creating a temporary tablespace for the index build to isolate I/O.
Celery is a really good framework for doing background task processing in Python (and other languages). While it is ridiculously easy to use celery, doing complex task flow has been a challenge in celery. (w.r.t task trees/graphs/dependecies etc.)
This talk introduces the audience to these challenges in celery and also explains how these can be fixed programmatically and by using latest features in Celery (3+)
Faster PHP apps using Queues and WorkersRichard Baker
PHP apps typically perform tasks in a synchronous manner; Resizing an image or sending a push notification. For most applications this works well, but as apps grow or experience increased traffic, each task adds extra milliseconds to a request, leaving users waiting.
A common solution is to defer these tasks to the background using a cron task. However, there is a better way. Job queues not only help to decouple your application and improve resilience but will also cut request times.
In this talk I we’ll explore some common queue systems; the features and tradeoffs of each solution, what to queue, refactoring existing code into jobs, and running workers. By the end you’ll be ready to build your next app one job at a time.
How to add non root user account to netapp for commvaultAshwin Pawar
The document describes how to configure a non-root user in ONTAP 7-mode for NDMP and IntelliSnap backups. It involves creating a role with the required capabilities, a group assigned to that role, and a user added to that group. The user's NDMP password must also be set. For IntelliSnap backups, the user's credentials need to be added in the array management GUI.
In this talk we will explore how to organize component-centric code splitting with server side rendering and universal data fetching in React, when your application becomes large enough.
Talk description: When you have a large enough application, a single large bundle with all of your code becomes a problem for startup time. You need to start breaking your app into separate bundles and load them dynamically when needed.
How to split a single bundle into multiple is a well-solved problem with tools like Browserify and Webpack.
But now you need to find places in your application where you can decide to split off into another bundle and load it asynchronously. You also need a way to communicate between server and client, and organize server side rendering and implement universal data fetching for your application.
Even React Router team failed with this task
“We’ve tried and failed a couple of times”(https://reacttraining.com/react-router/web/guides/code-splitting/code-splitting-server-rendering)
I will show you how to solve this problem, we will use a great library called React Loadable.
Also, we will look at some solutions which you can achieve with React Router v4 and why they are not the best one.
For this talk, you will need some knowledge in React, Babel (ES6), Node, Webpack 2, Redux, and little bit React Router v4.
Celery is a distributed task queue that allows long-running processes to be executed asynchronously outside of the main request-response cycle. It uses message brokers like RabbitMQ to distribute jobs to worker nodes for processing. This improves request performance and allows tasks to be distributed across multiple machines. Common use cases include asynchronous tasks like email sending, long database operations, image/video processing, and external API calls.
Every system has capacity limit. When load goes beyond limit then app starts to respond slow and show error. Stress driven development help us to keep check on this limit all the time. This helps us find bottleneck, know limitation of system, optimize and keeps check on them.
The document discusses techniques and tools for optimizing Rails applications. It covers topics like benchmarking tools, caching, session storage options, and common performance issues in Rails like slow helper methods and associations. The document provides recommendations on optimizing actions, views, and controllers in Rails.
Performance Optimization of Rails ApplicationsSerge Smetana
The document discusses optimizing the performance of Ruby on Rails applications. It covers optimizing Ruby code, Rails code, database queries, using alternative Ruby implementations like JRuby, and optimizing for production environments including shared filesystems, load balancing, and the frontend. Specific optimizations discussed include rewriting parts of the Date class in C, template inlining in Rails, pushing SQL conditions into subqueries, and using memcached instead of filesystem caching on a shared network.
Queues can provide parallel processing, cross language scripting and more! The talk was focused on Gearman but the principles apply to any alternative.
in last Seven Peaks Speaks android webinar: How to code effectively with MAD, Fedor talked about Background Processing with Work Manager, where we will learn about the best practices for scheduling one-time and periodic background work with Jetpack Work Manager.
Deferrable Background work is extremely critical area for Android developers . With the onset of latest modifications in background processes/tasks in Oreo, Pie & even Q it has become very intricate & cumbersome dealing with background tasks within our app. Developers always struggle in choosing from different available alternatives like Alarm Manager, Firebase Job Dispatcher , Job Scheduler , GCM Network Manager which fall short in implementing background work in an effective manner .There was an absence of a clean & centralised solution for background processing which will work from Kitkat to the latest version of Android seamlessly.
In this talk, we will look into new Work Manager APIs introduced as new Android Architecture Components & part of Android Jetpack. We will understand where we should & should not use WorkManager. We will dive into the different mechanisms provided by WorkManager to monitor work via LiveData.
We will unravel how we constrain ,monitor and cancel work. Chained, Parallel, Periodic and Unique work will also be explained in detail with examples. Since the APIs are stable this will help us to analyse & use WorkManager effectively in our app for different situations.
The document discusses Android job scheduling and provides details about the JobScheduler API. It defines scheduling, compares the AlarmManager and JobScheduler, and describes how to implement and schedule jobs using the JobScheduler. Examples are provided to demonstrate how to create a JobService, schedule jobs with criteria like network availability, and ensure jobs are persisted across device reboots.
This document outlines a project to build FuzzyDbg, a debugger with fuzzing functionality. It will allow debugging and testing binaries using a fuzzing engine. The implementation will include a generic debugger interface, program state dumping, and an automated mutation engine to generate input logs and crash logs. Key features will include attaching to processes, setting breakpoints, and viewing registers. Major modules will include the debugger interface, helper utilities, breakpoints, ELF parsing, context handling, and process attaching. The project aims to integrate fuzzing via Radamsa to generate test cases and find bugs in the debugged binaries.
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)DicodingEvent
WorkManager is an API that makes it easy to schedule asynchronous tasks that need to run when various constraints are met. It supports one-off and periodic tasks, chained tasks with inputs and outputs, and allows constraints to be set on when tasks run. The latest version of WorkManager provides a better in-process scheduler, new diagnostic APIs, and lint checks. It also supports RxJava 3.
Bootstrapping a ML platform at Bluevine [Airflow Summit 2020]Noam Elfanbaum
Building a ML analytics platform into production using Apache Airflow at Bluevine. This includes:
- Migrating our ML workload to Airflow
- Hacking at Airflow to provide a semi-streaming solution
- Monitoring business sensitive processes
Android Best Practices - Thoughts from the TrenchesAnuradha Weeraman
Here are some of the key structural building blocks in Android that can be used to build the YAMBA app:
1. Activities - For the timeline view and preference screens.
2. Services - For the background process that fetches statuses from the server. This can be started on boot and stopped based on network connectivity.
3. ContentProviders - To store and retrieve statuses from local storage.
4. BroadcastReceivers - To listen for boot completed and network connectivity changes. Can start/stop the background service accordingly.
5. AsyncTasks - For fetching statuses from the server in the background without blocking the UI.
6. Intents - To start the background service from the BroadcastReceivers
We use Gearman for managing queue system. This covers why we should use a queue in many situations on web-based interface as well as server-side application.
RUN@TIMER is an application created by me on pure innovation concept. And I am glad to announce that I was asked a number of questions on it, but I passed it all and hoping for good marks now!
This document discusses different approaches for handling threading in Android apps, including AsyncTask for quick background work, IntentService for work that should continue after the user leaves the app, and WakefulIntentService for long-running work that requires keeping the device awake. It recommends using AsyncTask and retained fragments for work taking 1-15 seconds, IntentService and an event bus for 1-15 seconds, and WakefulIntentService and an event bus for work lasting 15+ seconds. All approaches require dealing with thread safety and have limitations like inability to directly update the UI. Sample code is provided.
This document provides a script to speed up the creation or rebuilding of large indexes in an Oracle database. The script optimizes index creation through several techniques: setting parameters to increase direct I/O size, sort area size, parallel execution degree, and enabling nologging mode. It also recommends creating a temporary tablespace for the index build to isolate I/O.
Celery is a really good framework for doing background task processing in Python (and other languages). While it is ridiculously easy to use celery, doing complex task flow has been a challenge in celery. (w.r.t task trees/graphs/dependecies etc.)
This talk introduces the audience to these challenges in celery and also explains how these can be fixed programmatically and by using latest features in Celery (3+)
Faster PHP apps using Queues and WorkersRichard Baker
PHP apps typically perform tasks in a synchronous manner; Resizing an image or sending a push notification. For most applications this works well, but as apps grow or experience increased traffic, each task adds extra milliseconds to a request, leaving users waiting.
A common solution is to defer these tasks to the background using a cron task. However, there is a better way. Job queues not only help to decouple your application and improve resilience but will also cut request times.
In this talk I we’ll explore some common queue systems; the features and tradeoffs of each solution, what to queue, refactoring existing code into jobs, and running workers. By the end you’ll be ready to build your next app one job at a time.
How to add non root user account to netapp for commvaultAshwin Pawar
The document describes how to configure a non-root user in ONTAP 7-mode for NDMP and IntelliSnap backups. It involves creating a role with the required capabilities, a group assigned to that role, and a user added to that group. The user's NDMP password must also be set. For IntelliSnap backups, the user's credentials need to be added in the array management GUI.
In this talk we will explore how to organize component-centric code splitting with server side rendering and universal data fetching in React, when your application becomes large enough.
Talk description: When you have a large enough application, a single large bundle with all of your code becomes a problem for startup time. You need to start breaking your app into separate bundles and load them dynamically when needed.
How to split a single bundle into multiple is a well-solved problem with tools like Browserify and Webpack.
But now you need to find places in your application where you can decide to split off into another bundle and load it asynchronously. You also need a way to communicate between server and client, and organize server side rendering and implement universal data fetching for your application.
Even React Router team failed with this task
“We’ve tried and failed a couple of times”(https://reacttraining.com/react-router/web/guides/code-splitting/code-splitting-server-rendering)
I will show you how to solve this problem, we will use a great library called React Loadable.
Also, we will look at some solutions which you can achieve with React Router v4 and why they are not the best one.
For this talk, you will need some knowledge in React, Babel (ES6), Node, Webpack 2, Redux, and little bit React Router v4.
Celery is a distributed task queue that allows long-running processes to be executed asynchronously outside of the main request-response cycle. It uses message brokers like RabbitMQ to distribute jobs to worker nodes for processing. This improves request performance and allows tasks to be distributed across multiple machines. Common use cases include asynchronous tasks like email sending, long database operations, image/video processing, and external API calls.
Every system has capacity limit. When load goes beyond limit then app starts to respond slow and show error. Stress driven development help us to keep check on this limit all the time. This helps us find bottleneck, know limitation of system, optimize and keeps check on them.
The document discusses techniques and tools for optimizing Rails applications. It covers topics like benchmarking tools, caching, session storage options, and common performance issues in Rails like slow helper methods and associations. The document provides recommendations on optimizing actions, views, and controllers in Rails.
Performance Optimization of Rails ApplicationsSerge Smetana
The document discusses optimizing the performance of Ruby on Rails applications. It covers optimizing Ruby code, Rails code, database queries, using alternative Ruby implementations like JRuby, and optimizing for production environments including shared filesystems, load balancing, and the frontend. Specific optimizations discussed include rewriting parts of the Date class in C, template inlining in Rails, pushing SQL conditions into subqueries, and using memcached instead of filesystem caching on a shared network.
Queues can provide parallel processing, cross language scripting and more! The talk was focused on Gearman but the principles apply to any alternative.
in last Seven Peaks Speaks android webinar: How to code effectively with MAD, Fedor talked about Background Processing with Work Manager, where we will learn about the best practices for scheduling one-time and periodic background work with Jetpack Work Manager.
Deferrable Background work is extremely critical area for Android developers . With the onset of latest modifications in background processes/tasks in Oreo, Pie & even Q it has become very intricate & cumbersome dealing with background tasks within our app. Developers always struggle in choosing from different available alternatives like Alarm Manager, Firebase Job Dispatcher , Job Scheduler , GCM Network Manager which fall short in implementing background work in an effective manner .There was an absence of a clean & centralised solution for background processing which will work from Kitkat to the latest version of Android seamlessly.
In this talk, we will look into new Work Manager APIs introduced as new Android Architecture Components & part of Android Jetpack. We will understand where we should & should not use WorkManager. We will dive into the different mechanisms provided by WorkManager to monitor work via LiveData.
We will unravel how we constrain ,monitor and cancel work. Chained, Parallel, Periodic and Unique work will also be explained in detail with examples. Since the APIs are stable this will help us to analyse & use WorkManager effectively in our app for different situations.
The document discusses Android job scheduling and provides details about the JobScheduler API. It defines scheduling, compares the AlarmManager and JobScheduler, and describes how to implement and schedule jobs using the JobScheduler. Examples are provided to demonstrate how to create a JobService, schedule jobs with criteria like network availability, and ensure jobs are persisted across device reboots.
This document outlines a project to build FuzzyDbg, a debugger with fuzzing functionality. It will allow debugging and testing binaries using a fuzzing engine. The implementation will include a generic debugger interface, program state dumping, and an automated mutation engine to generate input logs and crash logs. Key features will include attaching to processes, setting breakpoints, and viewing registers. Major modules will include the debugger interface, helper utilities, breakpoints, ELF parsing, context handling, and process attaching. The project aims to integrate fuzzing via Radamsa to generate test cases and find bugs in the debugged binaries.
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)DicodingEvent
WorkManager is an API that makes it easy to schedule asynchronous tasks that need to run when various constraints are met. It supports one-off and periodic tasks, chained tasks with inputs and outputs, and allows constraints to be set on when tasks run. The latest version of WorkManager provides a better in-process scheduler, new diagnostic APIs, and lint checks. It also supports RxJava 3.
Bootstrapping a ML platform at Bluevine [Airflow Summit 2020]Noam Elfanbaum
Building a ML analytics platform into production using Apache Airflow at Bluevine. This includes:
- Migrating our ML workload to Airflow
- Hacking at Airflow to provide a semi-streaming solution
- Monitoring business sensitive processes
Android Best Practices - Thoughts from the TrenchesAnuradha Weeraman
Here are some of the key structural building blocks in Android that can be used to build the YAMBA app:
1. Activities - For the timeline view and preference screens.
2. Services - For the background process that fetches statuses from the server. This can be started on boot and stopped based on network connectivity.
3. ContentProviders - To store and retrieve statuses from local storage.
4. BroadcastReceivers - To listen for boot completed and network connectivity changes. Can start/stop the background service accordingly.
5. AsyncTasks - For fetching statuses from the server in the background without blocking the UI.
6. Intents - To start the background service from the BroadcastReceivers
We use Gearman for managing queue system. This covers why we should use a queue in many situations on web-based interface as well as server-side application.
RUN@TIMER is an application created by me on pure innovation concept. And I am glad to announce that I was asked a number of questions on it, but I passed it all and hoping for good marks now!
The document discusses different approaches for writing job workers and servers in Perl, including using Parallel::Prefork for managing preforked processes, Server::Starter for hot-deploying servers, and Parallel::Scoreboard for monitoring prefork-based workers and servers. It provides code examples and compares the prefork and event-driven approaches.
PyGrunn2013 High Performance Web Applications with TurboGearsAlessandro Molina
TurboGears is a full-stack Python web framework that can be slowed down by its many features. The document provides tips to optimize TurboGears applications, such as only using necessary features, avoiding static file serving, leveraging caching strategically, and offloading work asynchronously. It also stresses that understanding how users interact with an application is key to optimization.
Prometheus and Docker (Docker Galway, November 2015)Brian Brazil
Brian Brazil is an engineer passionate about reliable systems who has worked at Google SRE and Boxever. He discusses Prometheus, an open source monitoring system he helped create. Prometheus offers inclusive monitoring of services, is manageable and reliable, integrates easily with other tools, and provides powerful querying and dashboards. It is efficient, scalable, and helps provide visibility into systems through its data model and labeling.
How many ways to monitor oracle golden gate-Collaborate 14Bobby Curtis
The document provides contact information for Bobby Curtis, a senior technical consultant specializing in Oracle GoldenGate and Oracle Enterprise Manager 12c. It lists his location, affiliations, areas of expertise, and contact details including his Twitter, blog, and email addresses. The document also provides links to registration and location pages for an upcoming training event from Enkitec and an overview of the topics to be covered, including monitoring approaches for Oracle GoldenGate.
Web workers allow JavaScript to run concurrently in separate threads. This prevents long-running scripts from locking up the browser. Workers run scripts independently of any user interface scripts and don't block the UI. Workers are created by specifying a JavaScript file and can communicate with the main thread via messaging. Workers don't have access to the DOM but can perform background tasks like number crunching, notifications, and search queries to improve performance.
Shinken is a full rewrite of Nagios in Python that aims to solve issues with scaling, high availability, and simplifying administration for modern IT infrastructures. Key features include built-in high availability, multi-level load balancing, support for multiple platforms, faster performance, and advanced business rules. The Shinken web interface focuses on aggregating related elements and showing dependencies to help both technical and non-technical users understand business impacts. Advanced modules allow for discovery, triggers for passive data, and templating to reduce configuration complexity.
6. Design Principles
Reduce Defer Coalesce
Reduce all background activity If background activity must be
performed, defer it to when
device is on charger
If it cannot be deferred,
coalesce it with other
background activity to reduce
wakeup overhead
10. Juxtaposition between Extended & Deep Doze
Doze Extended
Trigger Screen off, on battery, stationary Screen off , on battery
Timing
Successively increasing periods with
maintenance windows
Repeated N-minute periods with
maintenance windows
Restrictions
No Network Access
Jobs/Syncs deferred
No Wakelocks
Alarms deferred
No GPS/WiFi Scans
No Network Access
Jobs/Syncs deferred
Exit
Motion, screen on, alarm clock or device
charging
Screen on or device charging
11. Background Processing Limitations (Oreo)
● To Improve RAM / Battery performance.
● Restricting Background processes for different applications
○ Services run freely in foreground
○ Background services are stopped when idle.
○ Bound services are not affected.
● Limitations on Background Location Updates
○ When in Background apps to receive location updates only a few times each hour.
● Broadcast Restrictions (very short list of excluded implicit broadcasts)
13. App Standby Buckets
● Active
● Working Set
● Frequent
● Rare
● Never
Application is in
Active Bucket
Has a notification from the
app been clicked
Is a sync adapter being
used in foreground?
Is there a foreground
service running?
Has an activity been
launched?
Is the application not often
used?
Is the application used
regularly?
Is the application used most
days?
Application is in
Never Bucket
Application is in
Working Set Bucket
Application is in
Frequent Bucket
Application is in
Rare Bucket
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
Application is not
currently active
No
No
No
No
17. Work Manager
● WorkManager is the recommended solution for background execution, taking into
account all OS background execution limits.
● The work is guaranteed to run, even on app restart.
● Work Manager is backward compatible to API 14.
● Works with and without Google Play Services.
● It should be used for all deferrable and guaranteed background work.
18. Internal Mechanism of WorkManager
Work Manager
API
23+
Job scheduler
Has play
services?
Alarm Manager and broadcast
receiver
GCM Network Manager
Yes
Yes
No
No
19. Worker
● Synchronous and runs on background thread by default
● doWork() method is overridden and the task added in it.
● doWork() is called exactly once per Worker instance. A new Worker is created if a unit of
work needs to be rerun.
● A Worker is given a maximum of ten minutes to finish its execution and return a
ListenableWorker.Result. After this time has expired, the Worker will be signalled to
stop.
21. ListenableWorker
● Work asynchronously
● Instantiated at runtime by the WorkerFactory specified in the Configuration.
● startWork() method performs all the task and runs on the main thread.
● New instance of ListenableWorker is case of a new or restarted work.
● Maximum of ten minutes to finish execution.
● Return a ListenableWorker.Result
23. Work Manager Request Types (2/2)
1. One Time Request
a. It is used for non-repeating work which can be part of a chain
b. It could have an initial delay
c. It could be part of a chain or graph of work
2. Periodic Request
a. Used for tasks that need to execute periodically but interval has to be more than 15 minutes
which will be be in flex interval.
b. It cannot be part of a chain or graph of work
27. Demo
// Creating a periodic work request which will execute every 15 minutes
28. Add Constraints
// Create constraint for to specify battery level and network type
//Request object to report it to the server
29. Start the task
Before v2.1
// Enqueuing the work request to fire the Work request
After v2.1
// Enqueuing the work request to fire the Work request
30. Input/Output for the task
// Input data for task while creating a Worker
// Setting data as input for the worker
// Reading data in Worker class
// Setting output from worker
// Return the data back in Result
36. Chaining Work Example
Periodic Worker
(Fired every 30 minutes)
Get RemoteConfig Worker
(gets remote configuration)
BatteryStats Worker
(reads device’s battery info)
NetworkStats Worker
(reads network info)
ReportGenerator Worker
(creates report and send to server)
Initializes Remote Config Worker
Gets info from
network and set as
Output data
Read configurations from
RemoteConfig Worker &
output it’s data
Read data from
BatteryStats &
NetworkStats worker
Read configurations from
RemoteConfig Worker &
output it’s data
One Time Worker
Periodic Worker
44. Cancelling work
// Cancel work by work request ID
WorkManager.getInstance(this).cancelWorkById(workRequest.id)
// Cancel work by unique work tag
WorkManager.getInstance(this).cancelAllWorkByTag(String)
// Cancel work
WorkManager.getInstance(this).cancelUniqueWork(String)
52. Handle when Work is stopped
● ListenableWorker's ListenableFuture is always cancelled when the work is expected to stop.
● Accordingly you can use the cancellation listener also to receive the callback.
● Override void onStopped() method for Listenable Worker.
● By handling work stoppages ,we abide by the rules and facilitate clean up.
● Return values or Future results will be ignored.
● It is better to check for stoppages via boolean isStopped() method for ListenableWorker.
53. Custom configuration
Used for initializing WorkManager with custom configurations, like -
● Factory for Worker and ListenableWorkers
● Default executor for workers
● Custom Logging
● various Job Scheduler parameters
54. Dependency Injection in Worker
● WorkManager provides an abstract WorkerFactory class which our factory can use to instantiate workers.
Source - https://bit.ly/2ZF8TBQ
● Assisted Injection library provided by Square
Source - http://bit.ly/wmsamples
● Dagger2 Multi-binding
Source - https://bit.ly/2L7Afwm
57. References
● http://bit.ly/2ZuNRtT - Work Manager Series by Pietro Maggi
● http://bit.ly/2L7ZNK1 - Work Manager with RxJava by Paulina Sadowska
● http://bit.ly/2NLOkBk - Dagger 2 Setup with Work Manager by Tuan Kiet
● http://bit.ly/2HwX3DS - Listenable Future Explained
● http://bit.ly/2MKKUiL - Android Dev Summit Talk on Work Manager by Sumir Kataria & Rahul Ravikumar
● http://bit.ly/30LlZPt - Workout Your tasks with WorkManager by Magada Miu
● http://bit.ly/2MJKbyc - Android Developers Blog: Power series
● http://bit.ly/2LkCdII - Schedule tasks with WorkManager | Android Developers
● http://bit.ly/30M4DBQ - How does Android Optimize Battery Usage in New Releases?
● http://bit.ly/2L5MGc9 - An ~extended~ Doze mode (Android Development Patterns S3 Ep 3) - YouTube
● http://bit.ly/2ZC3n2P - Android Jetpack: easy background processing with WorkManager - YouTube