Android Development Android Background Processing 1 — Questions and Answers
Question 1: Which Jetpack library is the recommended solution for deferrable background work in Android?
- WorkManager (Correct answer)
- AsyncTask
- IntentService
- JobScheduler
Correct answer: WorkManager
WorkManager is the recommended Jetpack library for deferrable, guaranteed background work that is constraint-aware and battery-friendly.
Question 2: What is a coroutine in Kotlin?
- A lightweight concurrency primitive that can suspend and resume execution (Correct answer)
- A background thread
- A type of Android Service
- A database transaction
Correct answer: A lightweight concurrency primitive that can suspend and resume execution
Kotlin coroutines are lightweight concurrency primitives that allow you to write asynchronous, non-blocking code in a sequential style.
Question 3: Which coroutine dispatcher should be used for CPU-intensive tasks in Android?
- Dispatchers.Default (Correct answer)
- Dispatchers.Main
- Dispatchers.IO
- Dispatchers.Unconfined
Correct answer: Dispatchers.Default
Dispatchers.Default uses a shared thread pool optimized for CPU-intensive computation tasks like sorting and parsing.
Question 4: Which WorkManager class represents a single unit of background work?
- Worker (Correct answer)
- WorkRequest
- WorkTask
- BackgroundWorker
Correct answer: Worker
Worker is the class you extend to implement the background task logic in WorkManager, overriding the doWork() method.
Question 5: What is the purpose of Dispatchers.IO in Kotlin coroutines?
- For network and disk I/O operations (Correct answer)
- For UI updates
- For CPU computations
- For main thread callbacks
Correct answer: For network and disk I/O operations
Dispatchers.IO uses a larger thread pool optimized for blocking I/O operations like file reads, network calls, and database queries.
Question 6: What type of Android Service runs in a foreground process and shows a persistent notification?
- Foreground Service (Correct answer)
- Background Service
- Bound Service
- Intent Service
Correct answer: Foreground Service
A Foreground Service performs long-running operations visible to the user through a required persistent notification, giving it higher process priority.
Which Jetpack library is the recommended solution for deferrable background work in Android?