Modifying views in AsyncTask doInBackground() does not (always) throw exception

后端 未结 3 1453
傲寒
傲寒 2020-12-20 13:47

I just came across some unexpected behaviour when playing around with some sample code.

As \"everybody knows\" you cannot modify UI elements from another thread, e.g

3条回答
  •  渐次进展
    2020-12-20 14:18

    The checkThread() method of ViewRootImpl.java is responsible for throwing this exception. This check is suppressed using member mHandlingLayoutInLayoutRequest until performLayout() i.e all the initial drawing traversals are complete.

    hence it throws exception only if we use delay.

    Not sure if this is a bug in android or intentional :)

提交回复
热议问题