/Practice

Android in depth reels

Android in depth1 / 3
1 / 5

What it gives you

WorkManager stores your work in its own database, survives process death and reboots, applies constraints and retries with backoff. It chooses the right system scheduler for each Android version. It is the default answer for deferrable background work.

2 / 5

Unique work

Enqueue sync under a unique name with a KEEP or APPEND policy, so ten triggers in a minute become one job, not ten. Give each file upload its own unique name, such as upload- followed by the file ID.

3 / 5

Constraints and timing

Declare what the job needs: a network, an unmetered network for media, battery not low. Periodic work runs at most every 15 minutes and may wait in Doze. For sync right after a user action, use expedited work that falls back to normal work when its quota runs out.

4 / 5

A good worker

A worker reads its progress from the database, does a bounded amount of work, commits after each unit and checks isStopped. If the system stops it, it returns retry and the next run continues exactly where it left off.

In practiceNever do network work inside the FCM callback. Enqueue a worker instead.
Interview answer

Say it in the interview

On Android, sync runs in WorkManager under unique names, with network and battery constraints and exponential backoff. Workers are short, checkpoint after every unit and return retry when stopped. FCM messages only enqueue work; they never make the network call themselves.

WorkManager, properly
#android
Android in depth2 / 3
1 / 4

Foreground services changed

Android 12 stopped most apps from starting foreground services in the background. Android 14 requires each one to declare a type, such as dataSync. Android 15 limits dataSync services to about six hours in every 24. A long-running service is no longer a safe default.

2 / 4

User-initiated transfer jobs

From Android 14, a job started while the user is in your app can be marked user-initiated. It shows a notification, may run for a long time and is not bound by normal job quotas. It exists for exactly the big upload or download a user asked for.

3 / 4

Respect the user

The required notification should be useful: file name, percentage and a cancel button. If the user cancels, record it in your database so the transfer is not quietly restarted later.

Interview answer

Say it in the interview

For big transfers the user starts, we use user-initiated data transfer jobs on Android 14 and later, with a progress notification and a cancel action. We avoid depending on dataSync foreground services because of the type requirement and Android 15’s six-hour daily limit.

Long transfers on modern Android
#android#uploads
Android in depth3 / 3
1 / 5

Doze

When the phone sits still with its screen off, Doze batches background work into short maintenance windows. Jobs and alarms wait, so your sync may run minutes or hours later than you expected.

2 / 5

Standby buckets

Android ranks apps by recent use: active, working set, frequent, rare and restricted. Apps in the rare bucket get very few job runs and a limited number of high-priority FCM messages.

3 / 5

OEM battery managers

Some manufacturers add their own aggressive killers. Test on Xiaomi, Oppo, Vivo and Samsung phones, measure background runs per manufacturer, and guide users of critical apps to allow background activity.

4 / 5

Force Stop

Force Stop in settings cancels every scheduled job and alarm until the user opens the app again. Nothing you write can undo that.

In practiceTest with adb shell dumpsys deviceidle force-idle, and am set-standby-bucket to simulate rare.
Interview answer

Say it in the interview

We plan for Doze, standby buckets and OEM battery managers rather than fighting them. We track sync health per manufacturer, test on Xiaomi, Oppo, Vivo and Samsung, and give users of critical features a short guide to allow background activity.

Doze, standby buckets and OEM killers
#android