私たちが Android アプリケーションで知っているように、ビューをタッチするだけでMain/UI Thread
、それ以外の場合はCalledFromWrongThreadException
以下のメッセージでスローできます。
android.view.ViewRootImpl$CalledFromWrongThreadException:
Only the original thread that created a view hierarchy can touch its views.
しかし、 で 1 回だけタッチするとonCreate()
、この Exception はスローされず、「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();
}
なぜなのかご存知ですか?