# How do you keep an Android app running in the background?

> Keep an Android app running in the background: battery exemption, standby buckets, Doze tests with adb. From Android docs; Droidkeep phones run 24/7.

- URL: https://droidkeep.com/guides/how-to-keep-an-android-app-running-in-the-background/
- Last updated: 2026-11-16
- Publisher: Droidkeep (https://droidkeep.com)

**Quick answer — How do you keep an Android app running in the background?**

Keep the app in the foreground where you can, exempt it from battery optimization, and check its standby bucket with `adb shell am get-standby-bucket`. Android's Doze and App Standby rules hold back idle apps on every phone. A **Droidkeep** cloud phone removes the hardware side: it stays on 24/7 for the whole rental, from $2.97 for 30 days.

**In brief**

- **Doze**: on a device unplugged, still and with the screen off, Android suspends network access, ignores wake locks and defers jobs and alarms.
- **App Standby Buckets** (Android 9+): apps used less get fewer jobs and alarms; Android 12 adds a restricted bucket.
- **User fix**: put the app on the battery optimization exemption list.
- **Developer fix**: a foreground service for work the user expects to continue, `setExactAndAllowWhileIdle()` for critical alarms.

## How do you keep an app running, step by step?

**Five steps, from the Android documentation on Doze and App Standby.** Replace `PACKAGE` with the app's package name, which `adb shell pm list packages -3` shows.

1. **Leave the app in the foreground** — An app with an open activity is in the active bucket, the least limited one. On a phone kept for one app, simply leave it open.
2. **Exempt it from battery optimization** — Android's documentation names Settings > Battery > Battery Optimization. An exempted app can use the network and hold partial wake locks during Doze.
3. **Check its standby bucket** — Run adb shell am get-standby-bucket PACKAGE. A value above 10 (active) means Android is throttling it.
4. **Test it under Doze** — Run adb shell dumpsys deviceidle force-idle, wait, then adb shell dumpsys deviceidle unforce and adb shell dumpsys battery reset. Check the app recovered.
5. **Test it under App Standby** — Run adb shell dumpsys battery unplug and adb shell am set-inactive PACKAGE true, then am set-inactive PACKAGE false and am get-inactive PACKAGE.

*Check and test background limits with adb*

```bash
adb shell am get-standby-bucket PACKAGE

# Doze test
adb shell dumpsys deviceidle force-idle
adb shell dumpsys deviceidle unforce
adb shell dumpsys battery reset

# App Standby test
adb shell dumpsys battery unplug
adb shell am set-inactive PACKAGE true
adb shell am set-inactive PACKAGE false
adb shell am get-inactive PACKAGE
```

## Which Android limit affects which kind of work?

**Each mechanism hits different work, and each has its own way out.** Summary of the Android developer documentation, read on 16 November 2026.

*Android background limits from the Android documentation, what they hold back and how an app keeps working*

| Limit | Applies from | What it holds back | Way out |
| --- | --- | --- | --- |
| Doze | Android 6.0 | Network, wake locks, jobs, syncs, standard alarms | Exemption list; `setExactAndAllowWhileIdle()` for alarms |
| App Standby | Android 6.0 | Network and jobs of apps not used recently | Foreground use, a visible notification, the exemption list |
| Standby buckets | Android 9 | How often jobs and alarms run | Active use; exempted apps skip bucket limits |
| Restricted bucket | Android 12 | Jobs once a day in a 10-minute batch, one alarm a day | Use the app within 45 days on Android 12; "unrestricted" setting |

## What can you do if you did not build the app?

**Keep it open, exempt it, and open it now and then.** The exemption list is in Settings, as above. On Android 12 an app nobody interacts with for 45 days can fall into the restricted bucket; opening it resets that clock. Apps that the user marks as "unrestricted" in settings are exempt from the restricted bucket.

If the app still stops, it was not built to run unattended. Some apps stop on purpose to save data or to follow their own rules; many games do, as the [idle games page](https://droidkeep.com/idle-mobile-games-in-the-cloud/ "Can you play idle mobile games 24/7 in the cloud?") explains. The [24/7 apps page](https://droidkeep.com/run-android-apps-24-7/ "How do you keep Android apps running 24/7?") covers which apps are worth running all day.

## What should you do if you build the app?

**Use the tool Android designed for each kind of work.** For work the user expects to continue, such as playback or an upload, use a foreground service with its notification. For critical alarms, `setAndAllowWhileIdle()` or `setExactAndAllowWhileIdle()`, which fire at most once per 9 minutes per app in Doze. For messages, Firebase Cloud Messaging.

Android's guide warns against starting a foreground service only to avoid being judged idle. Google Play also forbids asking for a direct battery exemption unless Doze breaks the app's core function; task automation apps are one accepted case.

## Why does a cloud phone help?

**It removes the reasons a handset stops: unplugging, moving, sleeping screens and flat batteries.** Doze starts when a device is unplugged, still and dark; a phone in your pocket meets those conditions every night. A Droidkeep phone has no battery to run down and nobody to switch it off. The phone keeps running 24 hours a day for the whole rental, whether or not a screen is open; apps stay where you left them.

Android's own rules still run inside it, so the steps above still apply. According to Droidkeep's survey of 16 November 2026, keeping a phone on all month with per-minute billing cost $302.40 at GeeLark's $0.007 a minute; a Droidkeep 4 GB phone costs $2.97 for 30 days. The [ADB guide](https://droidkeep.com/guides/how-to-connect-adb-to-a-cloud-phone/ "How do you connect ADB to a cloud phone?") shows how to run the commands on it.

## Background app questions

### Do I need root to change these settings?

No. The exemption list is in Settings, and the `adb shell` commands above run without root.

### Does the Doze test break anything?

No. `unforce` and `battery reset` return the phone to normal. Run them after each test.

### Why does my app stop after a few hours anyway?

Low memory can also close background apps. Give the app more RAM by closing others, or use a larger phone size.

### Does a foreground service keep the app alive?

It marks the app as in use, so App Standby does not treat it as idle. Android's guide says to use one only for work the user expects to continue.

### Are task killers useful?

No. They close apps without choosing, which is the opposite of what a 24/7 app needs.

**Verdict**

- **Foreground, exempted, tested**: those three steps keep most apps running on Android 12.
- **A phone that never sleeps** does the rest: a Droidkeep phone stays on for the whole rental.

## Sources

1. [Optimize for Doze and App Standby](https://developer.android.com/training/monitoring-device-state/doze-standby) — Android Developers (read 2026-11-16)
2. [App Standby Buckets](https://developer.android.com/topic/performance/appstandby) — Android Developers (read 2026-11-16)
3. [Android Debug Bridge (adb)](https://developer.android.com/tools/adb) — Android Developers (read 2026-11-16)
4. [GeeLark pricing](https://www.geelark.com/pricing/) — GeeLark (read 2026-11-16)

**A phone that never sleeps** Keep 4: on 24/7 for 30 days, $2.97. [Rent Keep 4 for 30 days](https://droidkeep.com/app/checkout/?plan=p4-30d&product=keep-4&from=guides-how-to-keep-an-android-app-running-in-the-background&lang=en) · [All guides](https://droidkeep.com/guides/ "Which cloud phone guides does Droidkeep publish?")

---

Droidkeep: Droidkeep rents Android phones in the cloud that stay on 24/7: apps, idle games and automation keep running when your own screen is off, with the screen in the browser and ADB over the network. 4, 8 or 16 GB of RAM, from 1 day to 365 days. Paid in crypto, no KYC.
