Android Main Thread and background processing Flashcards

Understand the Single Thread model in Android

1
Q

What thread is created when an application launches

A

Main thread known as the UI thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two rules for Android’s single thread model?

A
  1. Don’t block the UI thread
  2. Do not access the UI thread from outside the UI thread (ie) from a worker thread
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why would blocking of the UI thread occur?

A

Performing resource intensive tasks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are worker threads

A

All other threads apart from the UI thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Do objects outside of the thread have access to the objects on the thread

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does ANR stand for and when can it happen?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you decide to run something on a worker thread

A

If it takes more than a few milliseconds to complete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is used for persistent background work?

A

Android WorkManager

How well did you know this?
1
Not at all
2
3
4
5
Perfectly