<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>其实我是一个程序员 &#187; Android</title>
	<atom:link href="http://liubin.nanshapo.com/category/android/feed/" rel="self" type="application/rss+xml" />
	<link>http://liubin.nanshapo.com</link>
	<description>编程是一种乐趣</description>
	<lastBuildDate>Thu, 08 Dec 2011 12:31:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>howto do git replace</title>
		<link>http://liubin.nanshapo.com/2011/03/04/howto-do-git-replace/</link>
		<comments>http://liubin.nanshapo.com/2011/03/04/howto-do-git-replace/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 05:39:13 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=406</guid>
		<description><![CDATA[代码提交后，如果还要再改一次，如何修改？ 首先在本地修改代码 再执行如下命令： git add ./ git commit &#8211;amend repo upload ./ &#8211;replace]]></description>
			<content:encoded><![CDATA[<p>代码提交后，如果还要再改一次，如何修改？</p>
<p>首先在本地修改代码<br />
再执行如下命令：</p>
<p>git add ./</p>
<p>git commit &#8211;amend</p>
<p>repo upload ./ &#8211;replace</p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2011/03/04/howto-do-git-replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>android的收彩信通知的过程解析</title>
		<link>http://liubin.nanshapo.com/2011/02/19/android-mms-receive/</link>
		<comments>http://liubin.nanshapo.com/2011/02/19/android-mms-receive/#comments</comments>
		<pubDate>Sat, 19 Feb 2011 09:48:13 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=400</guid>
		<description><![CDATA[这里对froyo(非标准)里mms模块收彩信的函数调用关系进行一点解说。这里只说的是收到彩信，但是还没有下载（设为手工下载） 首先，mms是通过WAPPUSH实现的，具体在com.android.internal.telephony包里的WapPushOverSms类。 这个类里除了构造函数，另一个public的就是dispatchWapPdu()了 仔细查看下，就会找到dispatchWapPdu_MMS()这个函数 private void dispatchWapPdu_MMS(byte[] pdu, int transactionId, int pduType, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; int&#160;headerStartIndex, int headerLength) { &#160; &#160; &#160; &#160; byte[]&#160;header = new byte[headerLength]; &#160; &#160; &#160; &#160; System.arraycopy(pdu, headerStartIndex, header, 0, header.length); &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>这里对froyo(非标准)里mms模块收彩信的函数调用关系进行一点解说。这里只说的是收到彩信，但是还没有下载（设为手工下载）<br />
首先，mms是通过WAPPUSH实现的，具体在com.android.internal.telephony包里的WapPushOverSms类。<br />
这个类里除了构造函数，另一个public的就是dispatchWapPdu()了</p>
<p>仔细查看下，就会找到dispatchWapPdu_MMS()这个函数</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Green;">private</span><span style="color: Gray;"> </span><span class="hl-types">void</span><span style="color: Gray;"> </span><span style="color: Blue;">dispatchWapPdu_MMS</span><span style="color: Olive;">(</span><span class="hl-types">byte</span><span style="color: Olive;">[]</span><span style="color: Gray;"> </span><span style="color: Blue;">pdu</span><span style="color: Gray;">, </span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">transactionId</span><span style="color: Gray;">, </span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">pduType</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="hl-types">int</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">headerStartIndex</span><span style="color: Gray;">, </span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">headerLength</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="hl-types">byte</span><span style="color: Olive;">[]</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">header</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span class="hl-types">byte</span><span style="color: Olive;">[</span><span style="color: Blue;">headerLength</span><span style="color: Olive;">]</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">System</span><span style="color: Gray;">.</span><span style="color: Blue;">arraycopy</span><span style="color: Olive;">(</span><span style="color: Blue;">pdu</span><span style="color: Gray;">, </span><span style="color: Blue;">headerStartIndex</span><span style="color: Gray;">, </span><span style="color: Blue;">header</span><span style="color: Gray;">, </span><span style="color: Maroon;">0</span><span style="color: Gray;">, </span><span style="color: Blue;">header</span><span style="color: Gray;">.</span><span style="color: Blue;">length</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="hl-types">int</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">dataIndex</span><span style="color: Gray;"> = </span><span style="color: Blue;">headerStartIndex</span><span style="color: Gray;"> + </span><span style="color: Blue;">headerLength</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="hl-types">byte</span><span style="color: Olive;">[]</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">data</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span class="hl-types">byte</span><span style="color: Olive;">[</span><span style="color: Blue;">pdu</span><span style="color: Gray;">.</span><span style="color: Blue;">length</span><span style="color: Gray;"> - </span><span style="color: Blue;">dataIndex</span><span style="color: Olive;">]</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">System</span><span style="color: Gray;">.</span><span style="color: Blue;">arraycopy</span><span style="color: Olive;">(</span><span style="color: Blue;">pdu</span><span style="color: Gray;">, </span><span style="color: Blue;">dataIndex</span><span style="color: Gray;">, </span><span style="color: Blue;">data</span><span style="color: Gray;">, </span><span style="color: Maroon;">0</span><span style="color: Gray;">, </span><span style="color: Blue;">data</span><span style="color: Gray;">.</span><span style="color: Blue;">length</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">Intent</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">intent</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">Intent</span><span style="color: Olive;">(</span><span style="color: Blue;">Intents</span><span style="color: Gray;">.</span><span style="color: Blue;">WAP_PUSH_RECEIVED_ACTION</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">intent</span><span style="color: Gray;">.</span><span style="color: Blue;">setType</span><span style="color: Olive;">(</span><span style="color: Blue;">WspTypeDecoder</span><span style="color: Gray;">.</span><span style="color: Blue;">CONTENT_MIME_TYPE_B_MMS</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">intent</span><span style="color: Gray;">.</span><span style="color: Blue;">putExtra</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">transactionId</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: Blue;">transactionId</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">intent</span><span style="color: Gray;">.</span><span style="color: Blue;">putExtra</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">pduType</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: Blue;">pduType</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">intent</span><span style="color: Gray;">.</span><span style="color: Blue;">putExtra</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">header</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: Blue;">header</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">intent</span><span style="color: Gray;">.</span><span style="color: Blue;">putExtra</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">data</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">, </span><span style="color: Blue;">data</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">mSmsDispatcher</span><span style="color: Gray;">.</span><span style="color: Blue;">dispatch</span><span style="color: Olive;">(</span><span style="color: Blue;">intent</span><span style="color: Gray;">, </span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">android.permission.RECEIVE_MMS</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li></ol></div>
<p>注意别混了， mSmsDispatcher.dispatch的第二个参数不是action的意思，而是权限，实际这个intent的action就是Intents.WAP_PUSH_RECEIVED_ACTION</p>
<p>然后，mms包（com.android.mms.transaction）下的onReceive会得到这个intent，进行处理<br />
在这个onReceive里，会调用内部类去执行：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ReceivePushTask</span><span style="color: Olive;">(</span><span style="color: Blue;">context</span><span style="color: Olive;">)</span><span style="color: Gray;">.</span><span style="color: Blue;">execute</span><span style="color: Olive;">(</span><span style="color: Blue;">intent</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li></ol></div>
<p>在这个内部类的doInBackground方法里，则会再继续根据pdu类型，来判断如何处理</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Blue;">Uri</span><span style="color: Gray;"> </span><span style="color: Blue;">uri</span><span style="color: Gray;"> = </span><span style="color: Blue;">p</span><span style="color: Gray;">.</span><span style="color: Blue;">persist</span><span style="color: Olive;">(</span><span style="color: Blue;">pdu</span><span style="color: Gray;">, </span><span style="color: Blue;">Inbox</span><span style="color: Gray;">.</span><span style="color: Blue;">CONTENT_URI</span><span style="color: Gray;">, </span><span style="color: Blue;">phoneId</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">// Start service to finish the notification transaction.</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">Intent</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">svc</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">Intent</span><span style="color: Olive;">(</span><span style="color: Blue;">mContext</span><span style="color: Gray;">, </span><span style="color: Blue;">TransactionService</span><span style="color: Gray;">.</span><span style="color: Green;">class</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">svc</span><span style="color: Gray;">.</span><span style="color: Blue;">putExtra</span><span style="color: Olive;">(</span><span style="color: Blue;">TransactionBundle</span><span style="color: Gray;">.</span><span style="color: Blue;">URI</span><span style="color: Gray;">, </span><span style="color: Blue;">uri</span><span style="color: Gray;">.</span><span style="color: Blue;">toString</span><span style="color: Olive;">())</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">svc</span><span style="color: Gray;">.</span><span style="color: Blue;">putExtra</span><span style="color: Olive;">(</span><span style="color: Blue;">TransactionBundle</span><span style="color: Gray;">.</span><span style="color: Blue;">TRANSACTION_TYPE</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">Transaction</span><span style="color: Gray;">.</span><span style="color: Blue;">NOTIFICATION_TRANSACTION</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">mContext</span><span style="color: Gray;">.</span><span style="color: Blue;">startService</span><span style="color: Olive;">(</span><span style="color: Blue;">svc</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li></ol></div>
<p>在TransactionService里，实际上会最终调用NotificationTransaction</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">type</span><span style="color: Gray;"> = </span><span style="color: Blue;">PduHeaders</span><span style="color: Gray;">.</span><span style="color: Blue;">MESSAGE_TYPE_NOTIFICATION_IND</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">((</span><span style="color: Blue;">ind</span><span style="color: Gray;"> != </span><span style="color: Green;">null</span><span style="color: Olive;">)</span><span style="color: Gray;"> &amp;&amp; </span><span style="color: Olive;">(</span><span style="color: Blue;">ind</span><span style="color: Gray;">.</span><span style="color: Blue;">getMessageType</span><span style="color: Olive;">()</span><span style="color: Gray;"> == </span><span style="color: Blue;">type</span><span style="color: Olive;">))</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">transaction</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">NotificationTransaction</span><span style="color: Olive;">(</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">TransactionService</span><span style="color: Gray;">.</span><span style="color: Green;">this</span><span style="color: Gray;">, </span><span style="color: Blue;">serviceId</span><span style="color: Gray;">,</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">transactionSettings</span><span style="color: Gray;">, </span><span style="color: Olive;">(</span><span style="color: Blue;">NotificationInd</span><span style="color: Olive;">)</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">ind</span><span style="color: Gray;">, </span><span style="color: Blue;">phoneId</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li></ol></div>
<p>在NotificationTransaction里，则会完成Notification事务</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: #ffa500;">// Don't try to download when data is suspended, as it will fail, so defer download</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Gray;">!</span><span style="color: Blue;">autoDownload</span><span style="color: Gray;"> || </span><span style="color: Blue;">dataSuspended</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">downloadManager</span><span style="color: Gray;">.</span><span style="color: Blue;">markState</span><span style="color: Olive;">(</span><span style="color: Blue;">mUri</span><span style="color: Gray;">, </span><span style="color: Blue;">DownloadManager</span><span style="color: Gray;">.</span><span style="color: Blue;">STATE_UNSTARTED</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">sendNotifyRespInd</span><span style="color: Olive;">(</span><span style="color: Blue;">status</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li></ol></div>
<p>到这里（sendNotifyRespInd），这个事务应该算结束了。</p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2011/02/19/android-mms-receive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XXX烧鸡步骤</title>
		<link>http://liubin.nanshapo.com/2011/02/14/xxx_flash/</link>
		<comments>http://liubin.nanshapo.com/2011/02/14/xxx_flash/#comments</comments>
		<pubDate>Mon, 14 Feb 2011 06:40:07 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=398</guid>
		<description><![CDATA[1。关机，拔电池 2。按住相机按钮的同时按电源键 3。sudo ./fastboot devices 确认设备链接成功 4。sudo ./fastboot erase userdata 删除用户数据 5。sudo ./fastboot flash boot boot_xxx.img 烧写boot信息 6。sudo ./fastboot flast system system_xxx.img 烧写 system镜像]]></description>
			<content:encoded><![CDATA[<p>1。关机，拔电池<br />
2。按住相机按钮的同时按电源键<br />
3。sudo ./fastboot devices 确认设备链接成功<br />
4。sudo ./fastboot erase userdata  删除用户数据<br />
5。sudo ./fastboot flash boot boot_xxx.img 烧写boot信息<br />
6。sudo ./fastboot flast system system_xxx.img 烧写 system镜像</p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2011/02/14/xxx_flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何让自己的应用在应用程序列表里排在前面</title>
		<link>http://liubin.nanshapo.com/2011/02/10/order-first-of-all-apps/</link>
		<comments>http://liubin.nanshapo.com/2011/02/10/order-first-of-all-apps/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 05:12:32 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=389</guid>
		<description><![CDATA[普通的android的home程序里的应用一览，应该是按照字母顺序升续排列的，不光是android，其它平台可能也类似，很多东西都有按字母排列这一功能，这也是angry bird起名的由来吧，a怎么排都靠前。那么我们自己的程序必须要遵守这个规则吗？如果用汉字岂不是要排到很后面去了？ 答案是有小窍门，可以把你的“汉字”的应用名排到前面去，那就是修改app_name的值 先看看如何做吧，以应用汇为例 在values/string.xml里有如下代码 &#60;resources&#62; &#160; &#60;string&#160;name=&#34;app_name&#34;&#62;\u0020掌上应用汇&#60;/string&#62; &#160; &#60;string&#160;name=&#34;label&#34;&#62;掌上应用汇&#60;/string&#62; &#60;/resources&#62; 怎么样，一下子就明白了吧，app_name前面应该是有个空格，这样可以保证这个程序甚至可以排到a开头的程序的前面 掌上应用汇做的比较巧妙]]></description>
			<content:encoded><![CDATA[<p>普通的android的home程序里的应用一览，应该是按照字母顺序升续排列的，不光是android，其它平台可能也类似，很多东西都有按字母排列这一功能，这也是angry bird起名的由来吧，a怎么排都靠前。那么我们自己的程序必须要遵守这个规则吗？如果用汉字岂不是要排到很后面去了？</p>
<p>答案是有小窍门，可以把你的“汉字”的应用名排到前面去，那就是修改app_name的值</p>
<p>先看看如何做吧，以应用汇为例<br />
在values/string.xml里有如下代码</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;">&lt;</span><span style="color: Green;">resources</span><span style="color: Olive;">&gt;</span></li>
<li><span style="color: Gray;">&nbsp; </span><span style="color: Olive;">&lt;</span><span style="color: Green;">string</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">app_name</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">&gt;</span><span style="color: Gray;">\u0020掌上应用汇</span><span style="color: Olive;">&lt;/</span><span style="color: Green;">string</span><span style="color: Olive;">&gt;</span></li>
<li><span style="color: Gray;">&nbsp; </span><span style="color: Olive;">&lt;</span><span style="color: Green;">string</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">label</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">&gt;</span><span style="color: Gray;">掌上应用汇</span><span style="color: Olive;">&lt;/</span><span style="color: Green;">string</span><span style="color: Olive;">&gt;</span></li>
<li><span style="color: Olive;">&lt;/</span><span style="color: Green;">resources</span><span style="color: Olive;">&gt;</span></li></ol></div>
<p>怎么样，一下子就明白了吧，app_name前面应该是有个空格，这样可以保证这个程序甚至可以排到a开头的程序的前面</p>
<p>掌上应用汇做的比较巧妙</p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2011/02/10/order-first-of-all-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用Handler也能同步操作</title>
		<link>http://liubin.nanshapo.com/2011/01/31/synchronous-operation-with-handler/</link>
		<comments>http://liubin.nanshapo.com/2011/01/31/synchronous-operation-with-handler/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 08:07:32 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[技术]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=385</guid>
		<description><![CDATA[用Handler多数是为了异步操作，不阻塞UI线程的操作，可以防止ANR等。 今天看com.android.internal.telephony.gsm.SimSmsInterfaceManager的实现发现如下操作： Handler mHandler = new Handler() { &#160; &#160; &#160; &#160; @Override &#160; &#160; &#160; &#160; public&#160;void handleMessage(Message msg) { &#160; &#160; &#160; &#160; &#160; &#160; switch&#160;(msg.what) { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; case&#160;EVENT_UPDATE_DONE: &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; synchronized&#160;(mLock) { &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>用Handler多数是为了异步操作，不阻塞UI线程的操作，可以防止ANR等。<br />
今天看com.android.internal.telephony.gsm.SimSmsInterfaceManager的实现发现如下操作：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Blue;">Handler</span><span style="color: Gray;"> </span><span style="color: Blue;">mHandler</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">Handler</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; @</span><span style="color: Blue;">Override</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span class="hl-types">void</span><span style="color: Gray;"> </span><span style="color: Blue;">handleMessage</span><span style="color: Olive;">(</span><span style="color: Blue;">Message</span><span style="color: Gray;"> </span><span style="color: Blue;">msg</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">switch</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">msg</span><span style="color: Gray;">.</span><span style="color: Blue;">what</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">case</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">EVENT_UPDATE_DONE</span><span style="color: Gray;">:</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">synchronized</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">mLock</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">// ..................</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">mLock</span><span style="color: Gray;">.</span><span style="color: Blue;">notifyAll</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">break</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">case</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">EVENT_LOAD_DONE</span><span style="color: Gray;">:</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">synchronized</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">mLock</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">// ..................</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">mLock</span><span style="color: Gray;">.</span><span style="color: Blue;">notifyAll</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">break</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">}</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: #ffa500;">// ..................</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span class="hl-types">boolean</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Blue;">updateMessageOnIccEf</span><span style="color: Olive;">(</span><span class="hl-types">int</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">index</span><span style="color: Gray;">, </span><span class="hl-types">int</span><span style="color: Gray;"> </span><span style="color: Blue;">status</span><span style="color: Gray;">, </span><span class="hl-types">byte</span><span style="color: Olive;">[]</span><span style="color: Gray;"> </span><span style="color: Blue;">pdu</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">// ........................</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">synchronized</span><span style="color: Olive;">(</span><span style="color: Blue;">mLock</span><span style="color: Olive;">)</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">Message</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">response</span><span style="color: Gray;"> = </span><span style="color: Blue;">mHandler</span><span style="color: Gray;">.</span><span style="color: Blue;">obtainMessage</span><span style="color: Olive;">(</span><span style="color: Blue;">EVENT_UPDATE_DONE</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">status</span><span style="color: Gray;"> == </span><span style="color: Blue;">STATUS_ON_ICC_FREE</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">// Special case FREE: call deleteSmsOnSim instead of</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #ffa500;">// manipulating the SIM record</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">mPhone</span><span style="color: Gray;">.</span><span style="color: Blue;">mCM</span><span style="color: Gray;">.</span><span style="color: Blue;">deleteSmsOnSim</span><span style="color: Olive;">(</span><span style="color: Blue;">index</span><span style="color: Gray;">, </span><span style="color: Blue;">response</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">else</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </span><span style="color: #ffa500;">// ........................</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">try</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">mLock</span><span style="color: Gray;">.</span><span style="color: Blue;">wait</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">InterruptedException</span><span style="color: Gray;"> </span><span style="color: Blue;">e</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">log</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">interrupted while trying to update by index</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">mSuccess</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li></ol></div>
<p>感觉很是巧妙<br />
在操作函数中（updateMessageOnIccEf），发送消息之后调用mLock.wait(),而在handler里处理消息结果的时候notifyAll()，感觉很是巧妙。</p>
<p>大家不一定能在实际中有什么用处，但是可以参考下</p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2011/01/31/synchronous-operation-with-handler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>从android的framebuffer里取图</title>
		<link>http://liubin.nanshapo.com/2011/01/13/grab-a-frame-in-android-frame-buffer/</link>
		<comments>http://liubin.nanshapo.com/2011/01/13/grab-a-frame-in-android-frame-buffer/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 10:00:42 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[freebuffer]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=382</guid>
		<description><![CDATA[在网上看到的 只需要如下命令即可： $ adb shell # cat /dev/graphics/fb0 > /sdcard/frame.raw 然后用FFMPEG转换为png $ IMAGE_RES=320&#215;480 $ RAW_IMAGE=frame.raw $ OUT_IMAGE=frame-%d.png $ #Download the raw data $ adb pull /sdcard/$RAW_IMAGE . $ ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s $IMAGE_RES \ -i $RAW_IMAGE -f image2 -vcodec png $OUT_IMAGE 可以参考http://my.opera.com/otaku_2r/blog/grab-a-frame-in-android-frame-buffer]]></description>
			<content:encoded><![CDATA[<p>在网上看到的</p>
<p>只需要如下命令即可：<br />
$ adb shell<br />
# cat /dev/graphics/fb0 > /sdcard/frame.raw</p>
<p>然后用FFMPEG转换为png<br />
$ IMAGE_RES=320&#215;480<br />
$ RAW_IMAGE=frame.raw<br />
$ OUT_IMAGE=frame-%d.png<br />
$ #Download the raw data<br />
$ adb pull /sdcard/$RAW_IMAGE .<br />
$ ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s $IMAGE_RES \<br />
-i $RAW_IMAGE -f image2 -vcodec png $OUT_IMAGE</p>
<p> 可以参考<a href="http://my.opera.com/otaku_2r/blog/grab-a-frame-in-android-frame-buffer">http://my.opera.com/otaku_2r/blog/grab-a-frame-in-android-frame-buffer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2011/01/13/grab-a-frame-in-android-frame-buffer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>线程问题引起的内存泄露</title>
		<link>http://liubin.nanshapo.com/2010/12/28/memory-leak-for-the-thread/</link>
		<comments>http://liubin.nanshapo.com/2010/12/28/memory-leak-for-the-thread/#comments</comments>
		<pubDate>Tue, 28 Dec 2010 06:15:34 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[leak]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[run]]></category>
		<category><![CDATA[start]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=375</guid>
		<description><![CDATA[最近解决的一个内存泄露，竟然是由于线程问题引起的 看看下面代码，如何？ new Thread(new Runnable() { &#160; &#160; &#160; &#160; &#160; &#160; public&#160;void run() { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; MessagingNotification.updateSendFailedNotificationForThread(ComposeMessageActivity.this, threadId); &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; }).run(); 有什么问题吗？ 对，这段代码生成了一个thread的对象，竟然调用了run方法，这引起了内存泄露。 必须改为start才行。 而run方法，只是调用了Runnable的run方法而已： // Thread.class public void run() { &#160; &#160; if&#160;(target != null) { &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>最近解决的一个内存泄露，竟然是由于线程问题引起的</p>
<p>看看下面代码，如何？</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">Thread</span><span style="color: Olive;">(</span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">Runnable</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span class="hl-types">void</span><span style="color: Gray;"> </span><span style="color: Blue;">run</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">MessagingNotification</span><span style="color: Gray;">.</span><span style="color: Blue;">updateSendFailedNotificationForThread</span><span style="color: Olive;">(</span><span style="color: Blue;">ComposeMessageActivity</span><span style="color: Gray;">.</span><span style="color: Green;">this</span><span style="color: Gray;">, </span><span style="color: Blue;">threadId</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Olive;">})</span><span style="color: Gray;">.</span><span style="color: Blue;">run</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li></ol></div>
<p>有什么问题吗？</p>
<p>对，这段代码生成了一个thread的对象，竟然调用了run方法，这引起了内存泄露。<br />
必须改为start才行。</p>
<p>而run方法，只是调用了Runnable的run方法而已：<br />
// Thread.class</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Green;">public</span><span style="color: Gray;"> </span><span class="hl-types">void</span><span style="color: Gray;"> </span><span style="color: Blue;">run</span><span style="color: Olive;">()</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Green;">if</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">(</span><span style="color: Blue;">target</span><span style="color: Gray;"> != </span><span style="color: Green;">null</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: Blue;">target</span><span style="color: Gray;">.</span><span style="color: Blue;">run</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; </span><span style="color: Olive;">}</span></li></ol></div>
<p>而start方法则不同</p>
<p>低版本的java有这个问题，不知道为什么Android2.2还有这个问题：<br />
<a href="http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=5869e03fee226ffffffffc40d4fa881a86e3:WuuT?bug_id=4533087">http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=5869e03fee226ffffffffc40d4fa881a86e3:WuuT?bug_id=4533087</a></p>
<p>按上面说法，生产一个Thread对象，会在构造器调用init方法，这个方法会把线程加入到一个group里，而从group里删除实在exit方法里做的，如果只调用run，这个exit方法则不会被调用。</p>
<p>结论就是如果用Thread，尽量都用start()<br />
myThread = new Thread(myRunnable);<br />
myThread.start();</p>
<p>如果是Runnable，可以用run<br />
myRunnable.run()</p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2010/12/28/memory-leak-for-the-thread/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>activity的启动方式（launch mode）</title>
		<link>http://liubin.nanshapo.com/2010/12/23/activity-launch-mode/</link>
		<comments>http://liubin.nanshapo.com/2010/12/23/activity-launch-mode/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 11:14:38 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[launch]]></category>
		<category><![CDATA[mode]]></category>
		<category><![CDATA[singleInstance]]></category>
		<category><![CDATA[singleTask]]></category>
		<category><![CDATA[singleTop]]></category>
		<category><![CDATA[standard]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=372</guid>
		<description><![CDATA[在android里，有4种activity的启动模式，分别为： &#8220;standard&#8221; (默认) &#8220;singleTop&#8221; &#8220;singleTask&#8221; &#8220;singleInstance&#8221; 它们主要有如下不同： 1. 如何决定所属task &#8220;standard&#8221;和&#8221;singleTop&#8221;的activity的目标task，和收到的Intent的发送者在同一个task内，除非intent包括参数FLAG_ACTIVITY_NEW_TASK。 如果提供了FLAG_ACTIVITY_NEW_TASK参数，会启动到别的task里。 &#8220;singleTask&#8221;和&#8221;singleInstance&#8221;总是把activity作为一个task的根元素，他们不会被启动到一个其他task里。 2. 是否允许多个实例 &#8220;standard&#8221;和&#8221;singleTop&#8221;可以被实例化多次，并且存在于不同的task中，且一个task可以包括一个activity的多个实例； &#8220;singleTask&#8221;和&#8221;singleInstance&#8221;则限制只生成一个实例，并且是task的根元素。 singleTop要求如果创建intent的时候栈顶已经有要创建 的Activity的实例，则将intent发送给该实例，而不发送给新的实例。 3. 是否允许其它activity存在于本task内 &#8220;singleInstance&#8221;独占一个task，其它activity不能存在那个task里；如果它启动了一个新的activity，不管新的activity的launch mode 如何，新的activity都将会到别的task里运行（如同加了FLAG_ACTIVITY_NEW_TASK参数）。 而另外三种模式，则可以和其它activity共存。 4. 是否每次都生成新实例 &#8220;standard&#8221;对于没一个启动Intent都会生成一个activity的新实例； &#8220;singleTop&#8221;的activity如果在task的栈顶的话，则不生成新的该activity的实例，直接使用栈顶的实例，否则，生成该activity的实例。 比如现在task栈元素为A-B-C-D（D在栈顶），这时候给D发一个启动intent，如果D是 &#8220;standard&#8221;的，则生成D的一个新实例，栈变为A－B－C－D－D。 如果D是singleTop的话，则不会生产D的新实例，栈状态仍为A-B-C-D 如果这时候给B发Intent的话，不管B的launchmode是&#8221;standard&#8221; 还是 &#8220;singleTop&#8221; ，都会生成B的新实例，栈状态变为A-B-C-D-B。 &#8220;singleInstance&#8221;是其所在栈的唯一activity，它会每次都被重用。 &#8220;singleTask&#8221;如果在栈顶，则接受intent，否则，该intent会被丢弃，但是该task仍会回到前台。 当已经存在的activity实例处理新的intent时候，会调用onNewIntent()方法 如果收到intent生成一个activity实例，那么用户可以通过back键回到上一个状态；如果是已经存在的一个activity来处理这个intent的话，用户不能通过按back键返回到这之前的状态。]]></description>
			<content:encoded><![CDATA[<p>在android里，有4种activity的启动模式，分别为：<br />
&#8220;standard&#8221; (默认)<br />
&#8220;singleTop&#8221;<br />
&#8220;singleTask&#8221;<br />
&#8220;singleInstance&#8221;</p>
<p>它们主要有如下不同：</p>
<p><strong>1. 如何决定所属task</strong><br />
&#8220;standard&#8221;和&#8221;singleTop&#8221;的activity的目标task，和收到的Intent的发送者在同一个task内，除非intent包括参数FLAG_ACTIVITY_NEW_TASK。<br />
如果提供了FLAG_ACTIVITY_NEW_TASK参数，会启动到别的task里。<br />
&#8220;singleTask&#8221;和&#8221;singleInstance&#8221;总是把activity作为一个task的根元素，他们不会被启动到一个其他task里。</p>
<p><strong>2. 是否允许多个实例</strong><br />
&#8220;standard&#8221;和&#8221;singleTop&#8221;可以被实例化多次，并且存在于不同的task中，且一个task可以包括一个activity的多个实例；<br />
&#8220;singleTask&#8221;和&#8221;singleInstance&#8221;则限制只生成一个实例，并且是task的根元素。<br />
singleTop要求如果创建intent的时候栈顶已经有要创建 的Activity的实例，则将intent发送给该实例，而不发送给新的实例。</p>
<p><strong>3. 是否允许其它activity存在于本task内</strong><br />
&#8220;singleInstance&#8221;独占一个task，其它activity不能存在那个task里；如果它启动了一个新的activity，不管新的activity的launch mode 如何，新的activity都将会到别的task里运行（如同加了FLAG_ACTIVITY_NEW_TASK参数）。<br />
而另外三种模式，则可以和其它activity共存。</p>
<p><strong>4. 是否每次都生成新实例</strong><br />
&#8220;standard&#8221;对于没一个启动Intent都会生成一个activity的新实例；<br />
&#8220;singleTop&#8221;的activity如果在task的栈顶的话，则不生成新的该activity的实例，直接使用栈顶的实例，否则，生成该activity的实例。<br />
比如现在task栈元素为A-B-C-D（D在栈顶），这时候给D发一个启动intent，如果D是 &#8220;standard&#8221;的，则生成D的一个新实例，栈变为A－B－C－D－D。<br />
如果D是singleTop的话，则不会生产D的新实例，栈状态仍为A-B-C-D<br />
如果这时候给B发Intent的话，不管B的launchmode是&#8221;standard&#8221; 还是 &#8220;singleTop&#8221; ，都会生成B的新实例，栈状态变为A-B-C-D-B。</p>
<p>&#8220;singleInstance&#8221;是其所在栈的唯一activity，它会每次都被重用。</p>
<p>&#8220;singleTask&#8221;如果在栈顶，则接受intent，否则，该intent会被丢弃，但是该task仍会回到前台。</p>
<p>当已经存在的activity实例处理新的intent时候，会调用onNewIntent()方法<br />
如果收到intent生成一个activity实例，那么用户可以通过back键回到上一个状态；如果是已经存在的一个activity来处理这个intent的话，用户不能通过按back键返回到这之前的状态。</p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2010/12/23/activity-launch-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android内存泄漏问题的排查</title>
		<link>http://liubin.nanshapo.com/2010/12/20/find-android-memory-leak/</link>
		<comments>http://liubin.nanshapo.com/2010/12/20/find-android-memory-leak/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 08:07:03 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[heap]]></category>
		<category><![CDATA[hprof]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[leak]]></category>
		<category><![CDATA[mat]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=367</guid>
		<description><![CDATA[稍好效果，请点击这里下载PDF版本 首先先检查下你有没有犯这些错误（内存泄露的主要原因）： 生命周期过长的对象（static），尤其是集合对象（List/Map等）作为cache等使用，如果没有将某个对象主动的从中清除的话，这个集合就会占用越来越多的内存，可以用WeakReference，如WeakHashMap，使得它持有的对象不增加对象的引用数。 Scope定义不对，方法的局部变量定义成类的变量，类的静态变量等。尽量使得变量作用域别太大。 异常时没有加finally{}来释放某些资源，比如Cursor。 Listener没有显式remove；内部类持有外部对象的隐式引用，不论是什么，如果有add方法，一定要想想是否需要remove方法。 图像对象是否在不用的时候释放了（((BitmapDrawable) d).getBitmap().recycle();） 以下是正文 1. 获取hprof信息 1.1. 使用脚本get_hprof.sh ./get_hprof.sh －－脚本内容见附录 运行此脚本之前，需要根据你的实际情况修改脚本，设置一下几个变量： # where is you sdk SDKPATH=. 这个是需要制定sdk/tools目录的位置，需要执行其下的adb和hprof-conv命令 # where will you want to save the log file TARGET_LOG_DIR=./hproflog log的保存位置 # which process will you want to generate log # etc,mms or com.android.mms for the full process name # we [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://liubin.nanshapo.com/wp-content/uploads/2010/12/memory_leak_analyze.pdf">稍好效果，请点击这里下载PDF版本</a></p>
<p>首先先检查下你有没有犯这些错误（内存泄露的主要原因）：<br />
生命周期过长的对象（static），尤其是集合对象（List/Map等）作为cache等使用，如果没有将某个对象主动的从中清除的话，这个集合就会占用越来越多的内存，可以用WeakReference，如WeakHashMap，使得它持有的对象不增加对象的引用数。<br />
Scope定义不对，方法的局部变量定义成类的变量，类的静态变量等。尽量使得变量作用域别太大。<br />
异常时没有加finally{}来释放某些资源，比如Cursor。<br />
Listener没有显式remove；内部类持有外部对象的隐式引用，不论是什么，如果有add方法，一定要想想是否需要remove方法。<br />
图像对象是否在不用的时候释放了（((BitmapDrawable) d).getBitmap().recycle();）</p>
<p>以下是正文</p>
<p>1. 获取hprof信息</p>
<p>1.1. 使用脚本get_hprof.sh</p>
<p>./get_hprof.sh<br />
－－脚本内容见附录</p>
<p>运行此脚本之前，需要根据你的实际情况修改脚本，设置一下几个变量：<br />
# where is you sdk<br />
SDKPATH=.<br />
这个是需要制定sdk/tools目录的位置，需要执行其下的adb和hprof-conv命令</p>
<p># where will you want to save the log file<br />
TARGET_LOG_DIR=./hproflog<br />
log的保存位置</p>
<p># which process will you want to generate log<br />
# etc,mms or com.android.mms for the full process name<br />
# we will grep the NAME field of `ps` command<br />
# to identify the process id<br />
PKG=mms<br />
需要取得的进程名或者一部分，比如mms可以取得com.android.mms的进程信息</p>
<p># eclipse project path to show the hprof report<br />
ECLIPSE_PROJECT_PATH=/home/liubin/workspace_old/hprof/<br />
取得.hprof文件会被自动拷贝到eclipse工程下，用mat进行分析<br />
1.2. MAT的安装</p>
<p>eclipse 3.5的话，直接在install new software 菜单里安装：</p>
<p>其它版本的安装请参考eclipse的官方网站。</p>
<p>2. 使用MAT</p>
<p>如果安装成功MAT，就可以查看hprof报告了，在项目里双击生成的.hprof文件，即可查看。双击之后会弹出一个选择框，询问我们会干什么，选在第一个生成可疑报告就行了（不选也可以）：<br />
当然，如果不想每次都显示这个窗口，可以去掉界面中唯一一个可以打勾的地方。</p>
<p>如果在上面的界面里选择取消，则先显示主界面如下：</p>
<p>Overview里面的下方，有3栏菜单，第一个柱状图用来显示各个对象的情况，DominatorTree则显示占用heap比较多的对象，类似的，Top Consumers等，看说明都能知道是干什么的。</p>
<p>这里只说两个方面的，一个是Reports栏的Leak Suspects,生成可以报告，和DominatorTree，查找比较占用内存的对象。</p>
<p>2.1. Leak Suspects</p>
<p>单击Overview页面的［LeakSuspects］链接，即可生产可以报告，如图所示。对于可疑的对象，会罗列出来，比如problem suspect1，problem suspect2等，并且以饼状图形显示出来。</p>
<p>并且，会在下面接着列出来主要的（值得怀疑的）对象：</p>
<p>点击了&#8221;Details&#8221;链接之后，除了在上一页看到的描述外，还有Shortest Paths To the Accumulation Point和Accumulated Objects部分，这里说明了从GC root到聚集点的最短路径，以及完整的reference chain。<br />
每个带链接的东西都是可以点的。<br />
接着往下看，来到了Accumulated Objects by Class区域，顾名思义，这里能找到被聚集的对象实例的类名</p>
<p>2.2. Dominator tree 视图<br />
打开这个视图，会看到顶层的对象及占用heap的大小和百分比。单击对象前的三角形，可以查看对象间的（持有）关系。（注意，不一定是引用关系）<br />
按百分比或者Retained Heap倒序排序，即可发现有问题的对象<br />
shallow heap 是一个对象消耗掉的内存<br />
retained heap 是这个对象如果被回收的话，总共会释放多少内存<br />
比如对象a保有b和c两个对象，如果a被回收，则b和c的内存也会连带被回收。</p>
<p>注意：ClassName栏的第一行可以输入filter，比如mms等，<br />
其它界面也可以进行对结果的过滤。</p>
<p>展开某一对象（如上图的第一条），即可查看其持有heap详细：<br />
注意，某一对象的Retained Heap等数值是其子子节点的和，孙子不能重复计算。</p>
<p>想知道是谁引用了占有大量heap空间的对象而导致其不能被释放的原因，可以在选中的对象上点击右键，选择“Path to GC Roots”-&gt; “exclude weak/ soft references”，即可显示引用关系，见下图所示。从图中，可以看到，问题应该出现在mListeners这个变量上了。</p>
<p>附录1<br />
推荐几个网址：</p>
<p>http://www.eclipse.org/mat/</p>
<p>http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/7680</p>
<p>http://blog.csdn.net/xtyyumi301/archive/2008/10/04/3015493.aspx</p>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2010/12/20/find-android-memory-leak/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>android内存泄露(memory leak)之进程HProf (Heap Profile) 信息</title>
		<link>http://liubin.nanshapo.com/2010/12/17/android-memory-leak-get-hprof-heap-profile-info/</link>
		<comments>http://liubin.nanshapo.com/2010/12/17/android-memory-leak-get-hprof-heap-profile-info/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 08:02:40 +0000</pubDate>
		<dc:creator>liubin</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[hprof]]></category>

		<guid isPermaLink="false">http://liubin.nanshapo.com/?p=356</guid>
		<description><![CDATA[因为性能问题（主要是内存泄漏），需要采集程序堆栈等信息，代码如下，只是简单说几个地方： 1.默认的HProf (Heap Profile) 放在/data/misc，需要改写权限为777 2.kill -10 pid 即可生成.prof文件 3.需要用android sdk的hprof-conf将android的hprof转化为标准的(能在MAT中用的) #!/bin/sh &#160; # author liubin (http://liubin.nanshapo.com) # get_hprof.sh 2010/12/17 &#160; ######################################################## ###########&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ############### ###########&#160; &#160;you may change this area&#160; &#160;############### ###########&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>因为性能问题（主要是内存泄漏），需要采集程序堆栈等信息，代码如下，只是简单说几个地方：<br />
1.默认的HProf (Heap Profile) 放在/data/misc，需要改写权限为777<br />
2.kill -10 pid 即可生成.prof文件<br />
3.需要用android sdk的hprof-conf将android的hprof转化为标准的(能在MAT中用的)</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">#!/bin/sh</li>
<li>&nbsp;</li>
<li># author liubin (http://liubin.nanshapo.com)</li>
<li># get_hprof.sh 2010/12/17</li>
<li>&nbsp;</li>
<li>########################################################</li>
<li>###########&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ###############</li>
<li>###########&nbsp; &nbsp;you may change this area&nbsp; &nbsp;###############</li>
<li>###########&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ###############</li>
<li>########################################################</li>
<li>&nbsp;</li>
<li># where is you sdk </li>
<li>SDKPATH=.</li>
<li># where will you want to save the log file</li>
<li>TARGET_LOG_DIR=./hproflog</li>
<li>&nbsp;</li>
<li># which process will you want to generate log</li>
<li># etc,mms or com.android.mms for the full process name</li>
<li># we will grep the NAME field of `ps` command </li>
<li># to identify the process id</li>
<li>PKG=mms</li>
<li>&nbsp;</li>
<li># eclipse project path to show the hprof report</li>
<li>ECLIPSE_PROJECT_PATH=/home/liubin/workspace_old/hprof/</li>
<li>&nbsp;</li>
<li>&nbsp;</li>
<li>########################################################</li>
<li>###########&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #############</li>
<li>###########&nbsp; you may NOT change this area&nbsp; #############</li>
<li>###########&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #############</li>
<li>########################################################</li>
<li>&nbsp;</li>
<li># adb path</li>
<li>ADB=$SDKPATH/adb</li>
<li># hprof-conv path</li>
<li>HPROFCONV=$SDKPATH/hprof-conv</li>
<li>#echo $ADB</li>
<li>#exit</li>
<li>&nbsp;</li>
<li>&nbsp;</li>
<li>&nbsp;</li>
<li># check if the log directory exist </li>
<li>if [ -d $TARGET_LOG_DIR ]; then</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;using Log directory: $TARGET_LOG_DIR&quot;</li>
<li>else</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;create not exists directory $TARGET_LOG_DIR&quot;</li>
<li>&nbsp;&nbsp; &nbsp;mkdir $TARGET_LOG_DIR </li>
<li>&nbsp;&nbsp; &nbsp;if [ &quot;$?&quot; != 0 ]; then</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;echo &quot;Create Log directory ERROR !!!!!&quot;</li>
<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit 1</li>
<li>&nbsp;&nbsp; &nbsp;fi</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;using new log directory: $TARGET_LOG_DIR&quot;</li>
<li>fi</li>
<li>&nbsp;</li>
<li># make /data/misc writable</li>
<li>$ADB shell chmod 777 /data/misc</li>
<li>&nbsp;</li>
<li># fetch the pid of $PKG</li>
<li>pid=`$ADB shell ps | grep $PKG&nbsp; | awk '{print $2;}'`</li>
<li>echo &quot;$PKG pid is $pid&quot;</li>
<li>&nbsp;</li>
<li># send -10 signal to the $PKG process to generate a log file</li>
<li>$ADB shell kill -10 $pid</li>
<li>&nbsp;</li>
<li># select 3 sencond to wait for the complete of hprof file creating.</li>
<li># if not wait ,we may get the previous log </li>
<li>sleep 3</li>
<li>&nbsp;</li>
<li># get the latest log file name</li>
<li>pfile=`$ADB shell ls -l /data/misc | grep hprof | grep $pid | awk '{print $7;}' | sort -r | head -n 1 | sed -e 's/[\n\r]//g'`</li>
<li>&nbsp;</li>
<li>#pfile=&quot;/data/misc/$pfile&quot;</li>
<li>echo &quot;new hprof file is $pfile&quot;</li>
<li>&nbsp;</li>
<li># pull to target directory</li>
<li>$ADB pull &quot;/data/misc/$pfile&quot; $TARGET_LOG_DIR </li>
<li>&nbsp;</li>
<li>if [ &quot;$?&quot; != 0 ]; then</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;adb pull error!&quot;</li>
<li>else</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;pull log from avd ok&quot;</li>
<li>fi</li>
<li>&nbsp;</li>
<li># convert to mat format</li>
<li>$HPROFCONV $TARGET_LOG_DIR/$pfile $TARGET_LOG_DIR&quot;/MAT_&quot;$pfile</li>
<li>&nbsp;</li>
<li>if [ &quot;$?&quot; != 0 ]; then</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;convert to mat format error!&quot;</li>
<li>else</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;convert to mat format ok&quot;</li>
<li>fi</li>
<li>&nbsp;</li>
<li>&nbsp;</li>
<li># copy to eclipse project</li>
<li>cp $TARGET_LOG_DIR&quot;/MAT_&quot;$pfile $ECLIPSE_PROJECT_PATH/</li>
<li>&nbsp;</li>
<li>if [ &quot;$?&quot; != 0 ]; then</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;copy to eclipse project error !&quot;</li>
<li>else</li>
<li>&nbsp;&nbsp; &nbsp;echo &quot;copy to eclipse project ok&quot;</li>
<li>fi</li></ol></div>
]]></content:encoded>
			<wfw:commentRss>http://liubin.nanshapo.com/2010/12/17/android-memory-leak-get-hprof-heap-profile-info/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

