Android Main Thread and background processing Flashcards
Understand the Single Thread model in Android
What thread is created when an application launches
Main thread known as the UI thread
What are the two rules for Android’s single thread model?
- Don’t block the UI thread
- Do not access the UI thread from outside the UI thread (ie) from a worker thread
Why would blocking of the UI thread occur?
Performing resource intensive tasks
What are worker threads
All other threads apart from the UI thread
Do objects outside of the thread have access to the objects on the thread
No
What does ANR stand for and when can it happen?
Application Not Responding, this can happen when the UI thread is performing a long operation such as a DB query or network request, ML algorithm or downloading files
How do you decide to run something on a worker thread
If it takes more than a few milliseconds to complete
What is used for persistent background work?
Android WorkManager