Why cant a thread that is not the UI thread access the view?

后端 未结 3 1429
忘了有多久
忘了有多久 2021-01-22 07:22

I know that no thread can access the current view unless it is the UI Thread. I am wondering why? Why does it matter which thread is changing the view? Is it a security reason?

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 07:52

    Android application uses Single Thread Model and this thread is responsible to dispatch various events to the UI elements. This single thread model has two rules :

    1. Do not block the UI thread
    2. Do not access the Android UI toolkit from outside the UI thread

    If you create a thread that uses View outside the UI thread then it violates the second rules.

提交回复
热议问题