The collation of a post:
Handler must the main thread be instantiated? The difference between New Handler () and New Handler (Looper.getmainlooper ())
If you instantiate without parameters: Handler Handler = new Handler (), then this will default to the current thread's Looper
Generally speaking, if your handler is to refresh the operating UI, then you need to run under the main thread.
Situation
1. To refresh the Ui,handler to use the main thread of the Looper. Then in the main thread Handler Handler = new Handler (), if in other threads, also to satisfy this function, to Handler Handler = new Handler (Looper.getmainlooper ());
2. Do not refresh the UI, just process the message. The current thread, if it is the primary thread, Handler Handler = new Handler (), not the main thread, Looper.prepare (); Handler Handler = new Handler (); Looper.loop () or handler handler = new Handler (Looper.getmainlooper ());
If instantiated, use Looper.getmainlooper () to represent the main UI thread to handle.
If not, because only the UI thread defaults to Loop.prepare (); Loop.loop (), other threads need to call these two manually, or they will complain.
Message.what,message.arg1,message.arg2,message.obj, what's the difference between them?
What is commonly used to distinguish between messages, such as when you pass in msg.what = 3;
Then the processing time to judge Msg.what = = 3 is not set up, is the case, said the news is what to do (oneself can distinguish)
As for arg1,arg2, in fact, that is, two data to pass, two int value, see what you want to do with it. If your data is just a simple int value, then use these two, more convenient.
In fact, here you have less to say, SetData (Bundle), the above two Arg is to pass a simple int, this is to pass complex data.
Msg.obj, this is the transfer of data, MSG can carry objects, in the Handlemessage, you can take this data out to do processing. However, if it's the same process, it's best to use the above SetData, which is typically used by messenger classes to pass serializable objects across processes, which consumes more performance than the above.
Http://www.cnblogs.com/xpxpxp2046/archive/2012/04/13.html
Two good posts:
Http://www.cnblogs.com/xpxpxp2046/archive/2012/04/13/2445395.html
Http://www.cnblogs.com/xpxpxp2046/archive/2012/04/13/2445355.html