Home > Mobile >  Why this code doesn't crash
Why this code doesn't crash

Time:10-04

CodePudding user response:

In the android neutron thread can not directly update the UI thread

CodePudding user response:

Update the UI thread in the child thread, this a year ago I a mistake operation, and suddenly found not collapse and normal operation,,,
I think Google should be to modify library automatic thread cutting,
Didn't go to explore the source, of course, can share,,,

CodePudding user response:

Supposedly the child thread collapse, but the main thread run normally, looks all right, in fact the child thread code is not effective,

CodePudding user response:

Just like in the child thread toast, although no flash back but toast also won't appear

CodePudding user response:

Don't understand kottlin (? Suspicious), name, not an error that is a possibility, you change the UI of the operation, actually in the main thread,

For example,
MTextView. PostDelayed (new Runnable () {
Public void the run () {

MTextView. SetText (" 111111111 ");

}
}, 2000);

Why don't the collapse?

CodePudding user response:

Does not collapse, when the XML within the textView for wide high match_parent for fixed values, or all, can update in a child thread, not collapse, look at the next should be related to the textView update mechanism

CodePudding user response:

And TextView didn't any relationship, the child thread can't update the UI is the rules of the Android

CodePudding user response:

reference 7 floor wang can reply:
and TextView didn't any relationship, the provisions of the child thread can't update the UI is Android
can I don't know can't update in the child thread? Or I also wonder why this code can't write this collapse why

CodePudding user response:

Set the text in your thread, type a few words, can wrap that, try again,

CodePudding user response:

Don't collapse, because no trigger ViewRootImpl requestLayout method, in fact the child thread can't update the UI, it is because will first call requestLayout method checkThread method to detect the thread, if you are set to wrap_content TextView height width, so basically every set the trigger of this method

CodePudding user response:

references to the tenth floor only funny reply:
didn't collapse, because there is no trigger ViewRootImpl requestLayout method, in fact the child thread can't update the UI, it is because will first call requestLayout method checkThread method to detect the thread, if you are set to wrap_content TextView height width, so basically every set trigger this method


Brother, steady ~
Only pay attention to update the UI have check the operation of the thread, have not seen the trigger condition carefully

CodePudding user response:

Can see my blog, just wrote a passage to update the UI thread not collapse
  • Related