
Need to remain scheduled for prompt execution even if the app closes or theįor persistent immediate work, you should use WorkManager with a They are important enough that they might Tasks which are important to the user or which you otherwise can't schedule forĭeferred execution at a later time. Immediate work encompasses tasks which need to execute right away. Information, see the asynchronous work guide. Key Term: Immediate impersistent work is essentially asynchronous work. Instead, perform work persistently using WorkManager. The following table lays out which approach you should take for each type of
You should insteadĬomplete such tasks through persistent work using WorkManager. Long-running and deferrable impersistent work.
Long-running and deferrable impersistent work: You shouldn't use. Guide on threading for recommended options. For Java programming language users, read the Immediate impersistent work: You should use Kotlin coroutinesįor immediate impersistent work. All persistent work: You should use WorkManager for all forms of. You should approach impersistent or persistent work differently: Impersistent work: No longer scheduled after the process ends.įigure 1: Types of background work. Persistent work: Remains scheduled through app restarts and device. Likewise, background work in each of these three categories can be either
Deferrable: Does not need to run right away. Long Running: May take some time to complete. Immediate: Needs to execute right away and complete soon. Common types of background workīackground work falls into one of three primary categories: In such cases, the app is running in theįoreground until the service's lifecycle ends.
The user subsequently navigates away from Note: Consider a case in which a foreground service starts while an activityįrom the app is visible to the user. Otherwise, the app is running in the foreground.
The app isn't running any foreground services that started while anĪctivity from the app was visible to the user. None of the app's activities are currently visible to the user. Definition of background workĪn app is running in the background when both the following conditions are Working on a machine learning (ML) model, or performing network requests. Long-running tasks include things like decoding a bitmap, accessing storage, In general, you should take any blocking tasks off the UI thread. This guide explains what qualifies as background work, defines background taskĬategories, provides you with criteria to categorize your tasks, and recommendsĪPIs that you should use to execute them. Performance and therefore a poor user experience. Doing work on the main thread can lead to poor Processing data in the background is an important part of creating an AndroidĪpplication that is both responsive for your users as well as a good citizen on