-
This problem has just been encountered.,Follow the source code of Android.,Roughly analyze it.。
Android In order to limit the update UI of sub-threads, a thread inspection mechanism is set up, for example, from the sub-thread pair, it can be seen through the error log, the location of the exception is in, literally, this method is used to check whether the thread that modifies the view is the main thread.
This check method is called in the view's requestLayout(), but requestLayout() is not called in some cases
if(mparent != null){
if (!The only explanation is that one of the above 2 ifs does not match, resulting in the subsequent checkthread() not being called, and the subthread successfully modifies the UI.
This may be in the early stage of the activity creation, the layout or other action initialization has not been completed, resulting in the thread check not occurring, and the specific problem needs to be studied to know.
You can try it, your first case, let the thread sleep for 2 seconds before the new thread changes the textview, and then change the UI and throw an exception.
-
It's not that the sub-thread can't be finer UI or that the sub-thread in the ui thread can't update the UI directly, what you're creating in OnCreate is a sub-thread that is attached to the main thread. What is created in the button is a child thread that is attached to the UI thread
-
For case b, you try to create a new thread in the class, and then call it in the setonclicklistener of button, there should be no problem. If it's in the setonclicklistener of the button, it should be considered an internal class.
-
There are two ways to do this:
By inheriting the thread class and rewriting the run method, multithreading is implemented by inheriting the runnable interface.
It mainly accepts data sent by the sub-thread and uses this data to update the UI with the main thread
The main function of the handler is mainly used for the processing of asynchronous messages
When a message is sent out by the sub-thread, it first enters a message queue (the main thread), and the function that sent the message returns immediately, and the handler in the main thread takes out the messages one by one in the message queue and then processes the messages. This enables cross-threaded UI updates (which are actually done in the main thread).
This mechanism is usually used to handle relatively time-consuming operations, such as time-consuming operations such as accessing the network, reading large files, and time-consuming operations.
In the vernacular a little bit of an introduction to its operation:
Android starts a main thread when the app is launched.
i.e. UI threads), if a time-consuming operation is required at this point, for example:
When reading data over the network, or reading a large local file, you can't put these operations in the main thread, if you put them in the main thread, the interface will freeze (this is why you will be prompted when you directly access the network in the main thread, as we mentioned in the previous article Android main thread can not access the network exception solution).
-
Non-UI threads in Android cannot operate on the UI, you can perform time-consuming operations on a separate thread, and then update the UI through the handler. Or you can use asynctask.
-
Take a look at some of the content on this blog and I think you'll be clear!
-
When an Android program starts running, a separate process is started. By default, all activities or services in this program (service and activity are just two of the components provided by Android, in addition to the content provider and broadcast receiver) will run in this process.
An Android program also has only one process by default, but there can be many threads under a process. Among these threads, there is a thread, which we call UI thread, which is created when the Android program is running, and is the main thread in the process, which is mainly responsible for controlling the display, update and control interaction of the UI interface. At the beginning of the creation of the Android program, a process presented a single-threaded model, and all tasks were run in a single thread.
Therefore, we believe that every function executed by UI Thread should take as little time as possible. Other time-consuming tasks (accessing the network, data, querying the database, etc.) should be performed by sub-threads to avoid blocking the main thread.
So, how does UI Thread work with other threads? The common methods are:
Generate a handler object of the main thread, and act as a listener to allow the child thread to push the message to the message quene of the main thread, so as to trigger the handlermessage() function of the main thread, let the main thread know the status of the child thread, and update the UI on the main thread.
What to do when you have a seizure.
Generally speaking, patients with epilepsy will also have some precursor symptoms before the seizure, such as paresthesia, chest tightness, epigastric discomfort, fear, salivation, inaudible sound, blurred vision, etc. Therefore, patients should leave dangerous situations such as on the road, by the pond, or in front of a fire as soon as possible before they are alerted to a seizure, and find a safe place to sit or lie down in time. The Epilepsy Center of Beijing Aviation General Hospital said that when the patient's family should find out the patient's seizures in time, so as to take preventive measures as soon as possible to prevent the occurrence of other accidental injuries. >>>More
According to the law, unless it is an authorized lawyer, no family member, including the suspect's spouse, parents, and children, can see the suspect before the case is concluded. Based on the current state of confusion, any speculation is superfluous. It is recommended that a lawyer be entrusted to communicate directly with the criminal suspect, professionally guide the follow-up steps, and from the standpoint of protecting the criminal suspect's rights, defend in accordance with the law, and argue on the basis of reason, so that the criminal suspect can avoid unnecessary prison in accordance with the law.
I think you should break up with your current boyfriend, because even if a man is incapable, it is not a big problem if he can't make money, but if he is not good to his girlfriend and loses his temper at every turn, then such a man must not want it, even if you still love him, but I advise you not to be with your boyfriend's friend, you can be single for a while first, or look at others first, because if you are with that man right now, it will not be good for you and for him! Hope my words help you! I wish you a happy day.
In real life, the learning machine is mainly the two brands of Reading Lang and Backgammon, monopolizing the learning machine market, it is very difficult for other industries to get in, when buying it is mainly for children to learn, you need to ask people how much memory of this, must be a book in elementary school, **The memory is relatively small, once you grow up, the memory test paper ** is more, the memory is one or the second point is to ask, some places are for you to operate it yourself, you go to find it, is there a place for the game? Some children will learn to carry it back, parents do not pay attention to it and make it a game console, pay attention to this, the most important point is to see whether this brand is right or wrong, some brands you scan people's code, come out, some **, in case people have piracy, it is not good, buy it and can't return, probably that's it, when you buy it, you mainly look at the price, it is to see your own poverty, you are poor to buy cost-effective, Buddha on the buy some more useful on the line.
After Wen Jiao bit off Tang Seng's toe, you just go to find that toe, if the toe is swallowed by Wen Jiao, take advantage of the fact that it is not digested and quickly eat Wen Jiao together, eating Tang Seng's meat can be immortal and cultivate into a positive fruit It may be a rumor that the heavenly realm or the Buddha realm deliberately released it, go back and see when this rumor first appeared to understand. After all, Wen Jiao and Monk Sha, the only two who may have eaten Tang monk meat, have not achieved positive results because of Tang monk meat.