The arguments in Handler.obtainmessage () are written like this:
Message android.os.Handler.obtainMessage (int what, int arg1, intarg2, Object obj)
Public final Message obtainmessage (int, int arg1, int arg2,object obj)
SINCE:API Level 1
Same as Obtainmessage (), except that it also sets the What, Obj,arg1,and arg2 values on the returned Message.
Parameters
What Value is assign to thereturned message.what field.
Arg1 Value to assign to thereturned message.arg1 field.
Arg2 Value to assign to thereturned message.arg2 field.
Obj Value to assign to thereturned message.obj field.
And the difference between Obtainmessage and new message in handler:
Obtainmessage () is a msg from the message pool does not need another space to open new
New needs re-application, low efficiency, obtianmessage can be recycled;
Use Handler.obtainmessage (), instead of msg = new Message ();
Because if there is already a Message object,that not being used by
Any one, the system would hand use this object,so you don ' t has to
Create and object and allocate memory.
It is also another example of the object recycling and reusing in Android.
Message msg = Mhandler.obtainmessage ();
Msg.what = Update_listview;
Msg.obj = current + "/" + Total + "songs";
This method was called from worker Thread,so we cannot the update UI from here.
Msg.sendtotarget ();
Then look at the following code:
Message msg = handler.obtainmessage (); = i; Msg.sendtotarget (); Message msg=new message (); Msg.arg1=i; Handler.sendmessage (msg);
The first is a message that is obtained from the handler class so that it can send messages directly to the handler object, and the second is to send the message directly by calling handler's Send Message method.
Android handler.obtainmessage ()