SOLFIND
Web Lens
Portal home

Background Work | Background work | Android Developers

https://developer.android.com/develop/background-work • 281 KB fetched
Open original page


Background Work | Background work | Android Developers

Skip to main content

Essentials

* Build AI experiences

* Build AI-powered Android apps with Gemini APIs and more.

*

Get started

* Get started

* Create your first app. Use Compose for UI and adaptive app development to support multiple device form factors.

*

Hello, world!

*

Developer Verification

*

Adaptive apps

*

Compose for UI

*

AI-powered IDE

*

Training

*

Monetization with Play ↗️

* Optimize by form factor

* Build apps that optimize the user experience on phones, tablets, foldables, cars, XR, and more.

*

Phones, tablets, foldables

*

Android for Cars

*

Android TV

*

Android XR

*

Googlebook

*

ChromeOS

*

Wear OS

* Build by category

* Learn to build for your use case by following Google's prescriptive and opinionated guidance.

*

Games

*

Camera & media

*

Social & messaging

*

Health & fitness

*

Productivity

*

Enterprise apps

* Get the latest

* Stay in touch with the latest releases throughout the year, join our preview programs, and give us your feedback.

*

Latest updates

*

Experimental updates

*

Android Studio preview

*

Jetpack & Compose libraries

*

Wear OS releases

*

Privacy Sandbox ↗️

Design & Plan

* Excellent Experiences

* Build the best experiences for your best users.

*

Learn more

* UI Design

* Design a beautiful user interface using Android best practices.

*

Design for Android

*

Mobile

*

Desktop experiences

*

XR Headsets & XR Glasses

*

AI Glasses

*

Widgets

*

Wear OS

*

Android TV

*

Android for Cars

* Architecture

* Design robust, testable, and maintainable app logic and services.

*

Introduction

*

Libraries

*

Navigation

*

Modularization

*

Testing

*

Kotlin Multiplatform

* Quality

* Plan for app quality and align with Play store guidelines.

*

Overview

*

Core value

*

User experience

*

Accessibility

*

Technical quality

*

Excellent Experiences

* Security

* Safeguard users against threats and ensure a secure Android experience.

*

Overview

*

Privacy

*

Permissions

*

Identity

*

Fraud prevention

Develop

* Gemini in Android Studio

* Your AI development companion for Android development.

*

Learn more

*

Get Android Studio

* Core areas

* Get the samples and docs for the features you need.

*

Samples

*

Multidevice support

*

User interfaces

*

Background work

*

Data and files

*

Connectivity

*

All core areas ⤵️

* Tools and workflow

* Use the IDE to write and build your app, or create your own pipeline.

*

Write and debug code

*

Build projects

*

Test your app

*

Performance

*

Command-line tools

*

Gradle plugin API

*

Android Bench

* Device tech

* Write code for form factors. Connect devices and share data.

*

Phones, tablets, foldables

*

ChromeOS

*

Android for Cars

*

Android TV

*

Android XR

*

Wear OS

*

Android Health

*

Better Together

*

All devices ⤵️

* Libraries

* Browse API reference documentation with all the details.

*

Android platform

*

Jetpack libraries

*

Compose libraries

*

Google Play services ↗️

*

Google Play SDK index ↗️

Google Play

* Play Console

* Publish your app or game and grow your business on Google Play.

*

Go to Play Console

*

Learn more ↗️

* Fundamentals

* Learn how to engage users, monitize, and secure your app.

*

Play Monetization

*

Play Integrity

*

Play Policies

*

Play Programs ↗️

* Games Dev Center

* Develop and deliver games. Get tools, downloads, and samples.

*

Overview

*

Play Asset Delivery

*

Play Games Services

*

Play Games on PC

*

Level Up guidelines

*

All Play guides ⤵️

* Libraries

* Browse API reference documentation with all the details.

*

Play Feature Delivery

*

Play In-app Updates

*

Play In-app Reviews

*

Play Install Referrer

*

Google Play services ↗️

*

Google Play SDK index ↗️

*

All Play libraries ⤵️

* Tools & resources

* Tools for publishing, promoting, and managing your app.

*

Android App Bundles

*

Brand & marketing

*

Play Console APIs ↗️

Blog

* the Android Developer's Blog

*

Read the latest

*

Explore the authors →

* Explore categories

*

Product News

Stay in the loop with the latest updates, feature releases, and behind-the-scenes looks at how we’re evolving.

*

Community

Discover stories from our users, spotlight features, and the collaborative projects that bring us all together.

*

How-tos

From quick tips to deep-dive tutorials, these step-by-step guides are designed to help you work smarter and faster.

*

Case Studies

Real-world results from real-world users. Explore how different teams use our tools to achieve their goals.

*

Events & Programs

Get the details on upcoming webinars, workshops, meetups, and special initiatives designed to help you grow.

*

Documentation

Access detailed manuals, API references, and technical specifications to help you build and integrate with confidence.

/

*
English

*
Deutsch

*
Español – América Latina

*
Français

*
Indonesia

*
Italiano

*
Polski

*
Português – Brasil

*
Tiếng Việt

*
Türkçe

*
Русский

*
עברית

*
العربيّة

*
فارسی

*
हिंदी

*
বাংলা

*
ภาษาไทย

*
中文 – 简体

*
中文 – 繁體

*
日本語

*
한국어

Android Studio

Sign in

*

Develop

*

Core areas

*

Background work

Overview

Guides

*

Essentials

*

More

*

Design & Plan

*

More

*

Develop

*

More

*

Overview

*

Guides

*

Google Play

*

More

*

Blog

*

More

*

Android Studio

*

Build AI experiences

*

Get started

*

Get started

*

Hello, world!

*

Developer Verification

*

Adaptive apps

*

Compose for UI

*

AI-powered IDE

*

Training

*

Monetization with Play ↗️

*

Optimize by form factor

*

Phones, tablets, foldables

*

Android for Cars

*

Android TV

*

Android XR

*

Googlebook

*

ChromeOS

*

Wear OS

*

Build by category

*

Games

*

Camera & media

*

Social & messaging

*

Health & fitness

*

Productivity

*

Enterprise apps

*

Get the latest

*

Latest updates

*

Experimental updates

*

Android Studio preview

*

Jetpack & Compose libraries

*

Wear OS releases

*

Privacy Sandbox ↗️

*

Excellent Experiences

*

Learn more

*

UI Design

*

Design for Android

*

Mobile

*

Desktop experiences

*

XR Headsets & XR Glasses

*

AI Glasses

*

Widgets

*

Wear OS

*

Android TV

*

Android for Cars

*

Architecture

*

Introduction

*

Libraries

*

Navigation

*

Modularization

*

Testing

*

Kotlin Multiplatform

*

Quality

*

Overview

*

Core value

*

User experience

*

Accessibility

*

Technical quality

*

Excellent Experiences

*

Security

*

Overview

*

Privacy

*

Permissions

*

Identity

*

Fraud prevention

*

Gemini in Android Studio

*

Learn more

*

Get Android Studio

*

Core areas

*

Samples

*

Multidevice support

*

User interfaces

*

Background work

*

Data and files

*

Connectivity

*

All core areas ⤵️

*

Tools and workflow

*

Write and debug code

*

Build projects

*

Test your app

*

Performance

*

Command-line tools

*

Gradle plugin API

*

Android Bench

*

Device tech

*

Phones, tablets, foldables

*

ChromeOS

*

Android for Cars

*

Android TV

*

Android XR

*

Wear OS

*

Android Health

*

Better Together

*

All devices ⤵️

*

Libraries

*

Android platform

*

Jetpack libraries

*

Compose libraries

*

Google Play services ↗️

*

Google Play SDK index ↗️

*

Play Console

*

Go to Play Console

*

Learn more ↗️

*

Fundamentals

*

Play Monetization

*

Play Integrity

*

Play Policies

*

Play Programs ↗️

*

Games Dev Center

*

Overview

*

Play Asset Delivery

*

Play Games Services

*

Play Games on PC

*

Level Up guidelines

*

All Play guides ⤵️

*

Libraries

*

Play Feature Delivery

*

Play In-app Updates

*

Play In-app Reviews

*

Play Install Referrer

*

Google Play services ↗️

*

Google Play SDK index ↗️

*

All Play libraries ⤵️

*

Tools & resources

*

Android App Bundles

*

Brand & marketing

*

Play Console APIs ↗️

*

the Android Developer's Blog

*

Read the latest

*

Explore the authors →

*

Explore categories

*

Product News

*

Community

*

How-tos

*

Case Studies

*

Events & Programs

*

Documentation

*

Android Developers

*

Develop

*

Core areas

*

Background work

Stay organized with collections

Save and categorize content based on your preferences.

Background work

Background work is any task your app needs to perform when it's not visible in the foreground,
such as fetching data from a server or processing images.

Navigating the complexities of background execution is key to building apps that are
"good citizens"--that is, resilient, responsive, and efficient applications that work
well on all devices.

About background tasks

Get started with background work

View the guide on choosing the right background work API for your use case, and consider it in the context of Android's process and app lifecycle.

Guide

Choose the right option

Choosing the right background work API can be complex. This page gives you clear guidance on when to use asynchronous work, WorkManager, foreground services, or an alternative choice. Learn which API is best for your specific use case.

View the guide

Guide

Process and app lifecycle

Explore the fundamental concepts of the Android process lifecycle and how it impacts your app's behavior and resource management. Learn how the system manages app processes based on activity state, enabling you to design resilient and efficient applications that respond gracefully to system-initiated terminations.

View the guide

Key solutions

Some of the more common APIs and tools for performing work in the background, include WorkManager, foreground services, alarms, and broadcasts. Each solution will have varying implications for the battery life of your users's devices.

WorkManager

WorkManager is the recommended solution for persistent background work on Android. Learn how to use this powerful library to schedule tasks that persist across app restarts and device reboots, and understand its key features for handling constraints and flexible retry policies.

Learn more

Foreground Services

Foreground services offer a powerful way to run tasks immediately that out not to be interrupted. Learn when and how to declare, launch, and stop a foreground service with a persistent notification, ensuring your app performs critical tasks without being terminated by the system.

Learn more

Alarms

Alarms are a critical tool for scheduling time-based work. This page explains how to use AlarmManager to schedule both exact and inexact alarms for tasks that must run at a specific time or within a given window, even when your app is not running. It also covers best practices for managing alarms and ensuring they are optimized for battery life.

Learn more

Broadcasts

Learn how to send and receive broadcasts to handle system events and messages from other apps. You'll also learn about context-registered and manifest-declared receivers and the modern system restrictions that apply to them.

Learn more

Background guidance by use case

The right solution varies by your use case. Android provides many task-specific APIs, which
are optimized for particular scenarios, and will often lead to greater power savings and
fewer restrictions than when using WorkManager and Foreground Services.

This section lists some of the more common use cases, and the recommended solution.

Location

Most use cases only require location when the user is engaging with the app. However, if your app needs to access location in the background, use the Fused Location Provider API. Leverage this API to get the cached last known location, or request periodic location updates.

Widgets

Update GlanceAppWidgets efficiently when the app is in the background by using the update method.

Bluetooth and Connected Devices

Use Bluetooth Low Energy (BLE) to communicate with peripheral devices in the background. Learn how to scan, connect, and maintain a persistent connection to devices while respecting system-level restrictions and conserving battery.

Step Tracking

For tracking steps on mobile devices, consider reading steps from Health Connect, the Android data store for Health & Fitness data.

User-Initiated Data Transfer

For user-initiated background tasks that involve data transfer (including download and upload) and are meant to keep the user informed on progress, use the User-Initiated-Data Transfer Job type. This job type is optimized for long-running data transfers, and is granted priority by the system.

Media Playback

Use the Media3 library to support background playback while your app is not visible to the user.

Understand power optimizations

Considering your background work's effects on power is crucial for creating high-quality Android apps. It allows you to build more resilient and battery-efficient apps by understanding how the system manages resources. Optimizing for power reduces battery drain, prevents your app from being terminated by the system, and delivers a smoother user experience.

Guide

Understand Power Management Resource Limits

The system prioritizes apps' requests for resources based on the device state, app state
and the app's standby bucket.

Learn more about how your app can work within the device's power management resource
limits to reliably execute work in the background.

View the guide

Guide

Keep the Device Awake

Your app may need to keep the device's CPU from going into the suspended state in order to complete critical work. This guide helps you select the most appropriate methods for keeping a device awake.

View the guide

Guide

Optimize for doze and standby

Learn how to adapt your app to Doze and App Standby to improve battery efficiency and enhance the user experience. By understanding these power-saving modes, you can ensure your app runs optimally while minimizing its impact on device battery life.

View the guide

Guide

Test power-related issues

Beginning with Android 9, devices have power-management features that affect all apps. Learn how to test your app to make sure it runs properly on all devices, including with features such as battery saver, App Standby Buckets, and background restrictions.

View the guide

Latest news

*

X

Follow @AndroidDev on X

*

YouTube

Check out Android Developers on YouTube

*

LinkedIn

Connect with the Android Developers community on LinkedIn

*
More Android

*

Android

*

Android for Enterprise

*

Security

*

Source

*

News

*

Blog

*

Podcasts

*
Discover

*

Gaming

*

Machine Learning

*

Health & Fitness

*

Camera & Media

*

Privacy

*

5G

*
Android Devices

*

Large screens

*

Wear OS

*

ChromeOS devices

*

Android for cars

*

Android TV

*
Releases

*

Android 17

*

Android 16

*

Android 15

*

Android 14

*

Android 13

*

Android 12

*

Android 11

*
Documentation and Downloads

*

Android Studio guide

*

Developers guides

*

API reference

*

Download Studio

*

Android NDK

*
Support

*

Report platform bug

*

Report documentation bug

*

Google Play support

*

Join research studies

*

Android

*

Chrome

*

Firebase

*

Google Cloud Platform

*

All products

*

Privacy

*

License

*

Brand guidelines

*

Manage cookies

*

Get news and tips by email

Subscribe

*
English

*
Deutsch

*
Español – América Latina

*
Français

*
Indonesia

*
Italiano

*
Polski

*
Português – Brasil

*
Tiếng Việt

*
Türkçe

*
Русский

*
עברית

*
العربيّة

*
فارسی

*
हिंदी

*
বাংলা

*
ภาษาไทย

*
中文 – 简体

*
中文 – 繁體

*
日本語

*
한국어

Links found on this page

  1. Skip to main content [direct]
  2. Essentials [direct]
  3. Get started [direct]
  4. Hello, world! [direct]
  5. Developer Verification [direct]
  6. Adaptive apps [direct]
  7. Compose for UI [direct]
  8. AI-powered IDE [direct]
  9. Training [direct]
  10. Monetization with Play ↗️ [direct]
  11. Phones, tablets, foldables [direct]
  12. Android for Cars [direct]
  13. Android TV [direct]
  14. Android XR [direct]
  15. Googlebook [direct]
  16. ChromeOS [direct]
  17. Wear OS [direct]
  18. Games [direct]
  19. Camera & media [direct]
  20. Social & messaging [direct]
  21. Health & fitness [direct]
  22. Productivity [direct]
  23. Enterprise apps [direct]
  24. Latest updates [direct]
  25. Experimental updates [direct]
  26. Android Studio preview [direct]
  27. Jetpack & Compose libraries [direct]
  28. Wear OS releases [direct]
  29. Privacy Sandbox ↗️ [direct]
  30. Design & Plan [direct]
  31. Learn more [direct]
  32. Design for Android [direct]
  33. Mobile [direct]
  34. Desktop experiences [direct]
  35. XR Headsets & XR Glasses [direct]
  36. AI Glasses [direct]
  37. Widgets [direct]
  38. Wear OS [direct]
  39. Android TV [direct]
  40. Android for Cars [direct]
  41. Introduction [direct]
  42. Libraries [direct]
  43. Navigation [direct]
  44. Modularization [direct]
  45. Testing [direct]
  46. Kotlin Multiplatform [direct]
  47. Overview [direct]
  48. Core value [direct]
  49. User experience [direct]
  50. Accessibility [direct]
  51. Technical quality [direct]
  52. Overview [direct]
  53. Privacy [direct]
  54. Identity [direct]
  55. Fraud prevention [direct]
  56. Develop [direct]
  57. Learn more [direct]
  58. Samples [direct]
  59. Multidevice support [direct]
  60. User interfaces [direct]
  61. Data and files [direct]
  62. Connectivity [direct]
  63. Write and debug code [direct]
  64. Build projects [direct]
  65. Test your app [direct]
  66. Performance [direct]
  67. Command-line tools [direct]
  68. Gradle plugin API [direct]
  69. Android Bench [direct]
  70. Android for Cars [direct]
  71. Android TV [direct]
  72. Android XR [direct]
  73. Wear OS [direct]
  74. Android Health [direct]
  75. Better Together [direct]
  76. Android platform [direct]
  77. Jetpack libraries [direct]
  78. Compose libraries [direct]
  79. Google Play services ↗️ [direct]
  80. Google Play SDK index ↗️ [direct]