Obtainmessage () is used from the message pool. One MSG does not need to be opened up. New
New requires a new application, which is less efficient and can be recycled by obtianmessage;
// Use handler. obtainmessage (), instead of MSG = new message (); // because if there is already an message object, that not be used by // any one, the system will hand use that object, so you don't have to // create and object and allocate memory. // It is also another example of object reconfiguring and reusing in Android. message MSG = mhandler. obtainmessage (); MSG. what = update_listview; MSG. OBJ = Current + "/" + total + "Songs"; // this method is called from worker thread, so we cannot update UI from here. MSG. sendtotarget ();
See the followingCode:
Message MSG = handler. obtainmessage (); MSG. arg1 = I; MSG. sendtotarget (); message MSG = new message (); MSG. arg1 = I; handler. sendmessage (MSG );
The first method is to get the message from the handler class, so that you can directly send a message to the handler object. The second method is to directly call the handler's message sending method to send a message.