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.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "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."]]