why a new Thread can touch view

40 Views Asked by At

as we know in Android applications we can touch views just from Main/UI Thread and otherwise an CalledFromWrongThreadException throws with below message:

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

but when I touch just 1 time at onCreate(), this Exception does not throw and "Hello Again!" sets on 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();
}

Do you know why?

0

There are 0 best solutions below