0

正如我们在 Android 应用程序中所知道的那样,我们可以仅从以下消息中触摸视图Main/UI Thread,否则CalledFromWrongThreadException会抛出以下消息:

android.view.ViewRootImpl$CalledFromWrongThreadException:
Only the original thread that created a view hierarchy can touch its views.

但是当我在 处仅触摸 1 次时onCreate(),此异常不会抛出并且“Hello Again!” 开始TextView

 TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv = findViewById(R.id.tv);

    new Thread(new Runnable() {
        @Override
        public void run() {
            tv.setText("Hello Again!");
        }
    }).start();
}

你知道为什么吗?

4

0 回答 0