some ui updates can run on Non_UI thread in special condition
why some ui updates can run on Non_UI thread in special condition? for example:
Textview textView;
public void onCreate(Bundle savedInstanceState) {
textView = (TextView) findViewById(R.id.my_text);
new Thread() {
textView.setText("i can change 开发者_运维技巧the textview's text");
}.start();
}
i'm confused when android to check if the ui action is running on the UI thread? some time later?
You are not actually setting the text in the other thread. The code to run in the new thread goes in the run
method, which you should implement. Here is the correct syntax:
new Thread() {
public void run(){
textView.setText("i can change the textview's text");
}
}.start();
remembre that the only thread who can change the UI is the UIThread,
so if you want to change your UI from another thread , you sould use the method runOnUIThread()
like this :
YourAcitivity.this.runOnUIThread(new Runnable(){
@Override
public void run(){
textView.setText("i can change the textview's text");
}
});
SECOND POINT : : in your thread , there is no method run()
精彩评论