Asynchronous background processing
Stay organized with collections
Save and categorize content based on your preferences.
Asynchronous work is the second component of background work, alongside
persistent work. While both persistent and asynchronous work take place in the
background, they are ultimately quite different.
Asynchronous work is that which:
- Takes place in the moment.
- Does not need to persist across app restarts or device reboots.
- Occurs off the main thread, or blocks the main thread.
This is in contrast to persistent work, which you may schedule for future
execution and which remains scheduled through app restarts and device reboots.
An example of asynchronous work may be sending an HTTP request off the main
thread, returning its result only when it arrives.
Java and Kotlin
The way you handle asynchronous work depends on the overall app architecture
you follow. If you are working with a Java Programming Language app, your needs
are different than if you are working with Kotlin.
|
Kotlin |
Java |
Solution |
Coroutines. |
Java threads. |
Further reading |
For a full overview of Coroutines, see the Coroutines guide. |
See the Java Threads page for more information. |
Further reading
For more information on persistent work, see the persistent work overview.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2023-12-15 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-12-15 UTC."],[],[],null,["# Asynchronous background processing\n\nAsynchronous work is the second component of background work, alongside\npersistent work. While both persistent and asynchronous work take place in the\nbackground, they are ultimately quite different.\n\nAsynchronous work is that which:\n\n- Takes place in the moment.\n- Does not need to persist across app restarts or device reboots.\n- Occurs off the main thread, or blocks the main thread.\n\nThis is in contrast to persistent work, which you may schedule for future\nexecution and which remains scheduled through app restarts and device reboots.\nAn example of asynchronous work may be sending an HTTP request off the main\nthread, returning its result only when it arrives.\n\nJava and Kotlin\n---------------\n\nThe way you handle asynchronous work depends on the overall app architecture\nyou follow. If you are working with a Java Programming Language app, your needs\nare different than if you are working with Kotlin.\n\n| | Kotlin | Java |\n| Solution | Coroutines. | Java threads. |\n| Further reading | For a full overview of Coroutines, see the [Coroutines guide](/kotlin/coroutines). | See the [Java Threads](/guide/background/asynchronous/java-threads) page for more information. |\n|-----------------|------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|\n\nFurther reading\n---------------\n\nFor more information on persistent work, see the [persistent work overview](/guide/background/persistent)."]]