Pages 207 to 209
How do you architect background sync that is reliable, battery-friendly, and respects user data usage preferences?
Common · Mid to senior
Short answer
I model synchronization as unique persistent work with explicit constraints, exponential backoff, idempotent operations, and durable progress. User settings shape network and charging constraints rather than relying on an always-running service.
Memorize this
Persist sync intent, constrain execution, make retries safe, and expose progress.
Senior answer
The data-usage angle: honor NetworkType.UNMETERED constraints for bulk sync, expose a user setting (sync on Wi-Fi only) mapped to constraints, respect Data Saver via ConnectivityManager.getRestrictBackgroundStatus and skip optional transfers when restricted, and batch small operations into single windows to reduce radio wakeups.
Why they ask
The interviewer is checking whether reliability, battery policy, data cost, and user control are designed together around Android background limits.
The trap
Ignoring Data Saver, syncing full media libraries over restricted metered connections. Many small independent sync jobs instead of one batched window.
Code
fun syncConstraints(wifiOnly: Boolean): Constraints =
Constraints.Builder()
.setRequiredNetworkType(
if (wifiOnly) NetworkType.UNMETERED
else NetworkType.CONNECTED
)
.setRequiresBatteryNotLow(true)
.build()
fun shouldSkipOptionalSync(cm: ConnectivityManager): Boolean =
cm.isActiveNetworkMetered &&
cm.restrictBackgroundStatus ==
ConnectivityManager
.RESTRICT_BACKGROUND_STATUS_ENABLEDFollow-up questions
• When should a user-initiated sync become expedited work?
• How do you prevent two triggers from starting overlapping synchronization runs?
Live interview wording
A unique WorkManager chain reads pending operations from durable storage and writes checkpoints transactionally. Constraints reflect the user's metered-network and charging choices. Retry handles transient failures with backoff, while authentication or validation failures become visible terminal states instead of loops.
Weak answer
“I would run a foreground service every fifteen minutes so synchronization cannot be killed.”
Interviewer push
The user disabled mobile-data sync, but an expedited refresh starts on a metered connection. Which policy layer should have blocked it?
Recovery line
“I would derive WorkManager constraints and runtime guards from the persisted user policy before any transfer begins.”
What earns the point
The candidate covers durable work, uniqueness, constraints, backoff, idempotency, user policy, observability, and terminal failure handling.


