转自:http://blog.csdn.net/u011791526/article/details/53540346
通常使用handler发送信息时,会使用下面两种方式
实际运用中,通常使用第二种方法或者第三种方法(其实是一样的,handler.obtainMessage最终也是调用了Message的obtain方法)。
在Message的官方文档中,有这样一句话:
While the constructor of Message is public, the best way to get one of these is to call Message.obtain() or one of the Handler.obtainMessage()
methods, which will pull them from a pool of recycled objects.
意思是说,虽然Message的构造方法是公共的(可以通过New操作创建一个Message对象),但获取实例最好的方式还是Message.obtain()或者 Handler.obtainMessage() ,这两种方法提供的对象是消息池中那些已经创建但不再使用的对象。节约了内存资源。
message的pool具体是怎么实现的,这篇文章讲的很详细了 点击打开链接