Most of the time, we need to implement the message mechanism is nothing more than a class to get the data, we need to pass to a main interface to display, you can put this message in the class global variables, the main interface class with a thread timed scan, if the data is not empty, then the class refresh, then update the main interface of the data, When the update is complete, the data is emptied so that the next time the judgment is empty, it is not updated until a subclass refreshes the location.
But even so, it is not so simple, such as I in the main program, the dead loop continuously output an int type variable value, using two try Catch statements, the first will not die, in the log window can see the increase in data, and the second is not executed, the text box does not increase the data on a regular basis
?
We need to use Java handler to do this, first of all in the main program, declare handler type variables, and then oncreate the time to do this function to do things (can point to a new function, or directly write, note that the function format is dead, The message type variable is required to come in, but what function is actually executed internally is arbitrary, for example, I want to execute Updatatalk, which is to update the main interface with a string.
?
To implement the message mechanism of the problem, our main program once OnCreate started a thread, the threads continue to use the first in this article, to determine whether a global string is empty or null, if not the description of the new data, to perform the update. Note that the start of thread T1 executes the Run method, judging and refreshing the data every 100ms. Can try a direct update when not, must be handed over to handler to deal with.
?
Of course, after the update, you have to clear the data, or you will continue to prompt the same words
?
?
How to implement message mechanism easily in JAVA eclipse