

1. What is WorkManager and why was it introduced?
Answer: It’s a Jetpack library for deferrable, asynchronous, and guaranteed background work. It was introduced to simplify background task management and handle various OS restrictions (Doze, App Standby, etc.) across different Android versions, providing a single, consistent API.
2. When should you use WorkManager? Give a few use cases.
Answer: For tasks that need to run reliably even if the app exits or the device restarts. Examples:
3. What are the key benefits of using WorkManager?
Answer:
E.g. Let’s say every hour the server is updated with new high quality images. Whenever we open our custom gallery app we should see almost synced data from the server.
Write following work requests in chain to happen in background.
Download -> Decompress -> Apply filter -> Save locally.
If not urgent do it on unmetered network type(Wifi or Broadband)
4. What is a Worker class? How do you define a unit of work in WorkManager?
Answer: A Worker is an abstract class you extend to define the actual background task. You override the doWork() method, which runs on a background thread provided by WorkManager.
5. Explain the Result types that doWork() can return.
Answer:
6. What are WorkRequests? What are the two main types?
Answer: WorkRequest defines how and when your work should run.
7. How do you enqueue a WorkRequest?
Answer: Using WorkManager.getInstance(context).enqueue(workRequest).
8. Explain WorkManager’s Constraints. Give examples of common constraints.
Answer: Constraints define the conditions that must be met for a WorkRequest to execute. Examples:
9. How do you pass input data to a Worker and retrieve output data from it?
Answer:
10. Describe Work Chaining. When would you use it?
Answer: Work chaining allows you to define a sequence or graph of WorkRequests where the output of one task can become the input of the next. Use cases:
11. How do you handle retries in WorkManager? Explain the backoff policy.
Answer: If doWork() returns Result.retry(), WorkManager will re-schedule the task based on its retry policy.