提问人:beigirad 提问时间:2/8/2019 更新时间:2/8/2019 访问量:34
为什么新的 Thread 可以触摸视图
why a new Thread can touch view
问:
正如我们所知,在Android应用程序中,我们可以触摸视图,否则会抛出以下消息:Main/UI Thread
CalledFromWrongThreadException
android.view.ViewRootImpl$CalledFromWrongThreadException:
Only the original thread that created a view hierarchy can touch its views.
但是当我只触摸 1 次时,这个异常不会抛出并且“Hello Again!onCreate()
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();
}
你知道为什么吗?
答: 暂无答案
评论
onCreate()
onStart()
tv's