我们在Android应用程序中知道,我们可以仅从Main/UI Thread
触摸视图,否则将抛出CalledFromWrongThreadException
并显示以下消息:
android.view.ViewRootImpl$CalledFromWrongThreadException:
Only the original thread that created a view hierarchy can touch its views.
但是当我仅在onCreate()
触摸1次时,不会抛出此异常,并且会再次“您好!”在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();
}
你知道为什么吗?