1

What specifically is the mechanism by which Android detects and enforces that certain types of operations only occur in the UI thread?

Are there just lots of places in the framework where the current thread is checked?

I imagine there's some more central way this is done, and I'd like to know where it is, and what it is.

This question is for the sake of knowledge alone. I do not have a specific problem I'm trying to solve.

Julian A.
  • 10,928
  • 16
  • 67
  • 107

2 Answers2

0

From what I have found – yes, it's made in more or less central way via Blockguard. It is a mechanism to let threads set restrictions on what code is allowed to do in their thread.

It's called in a low-level operations of IO, network access and so on, depending on current thread policy. You can find its usages here, for example.

Also there is some useful info in StrictMode description to dig in that direction.

Kirill Bubochkin
  • 5,868
  • 2
  • 31
  • 50
-1

long tasks, background task, using network and etc must be run on UI thread, for more information read this link

DolDurma
  • 15,753
  • 51
  • 198
  • 377