﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-&lt;script language="javascript" src="http://www.shi-ci.com/embeded.do"&gt;&lt;/script&gt;-随笔分类-android</title><link>http://www.blogjava.net/yglwxl/category/38427.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 19 Feb 2011 21:52:46 GMT</lastBuildDate><pubDate>Sat, 19 Feb 2011 21:52:46 GMT</pubDate><ttl>60</ttl><item><title>ContentProvider分析</title><link>http://www.blogjava.net/yglwxl/archive/2011/02/18/344618.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Fri, 18 Feb 2011 06:51:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2011/02/18/344618.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/344618.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2011/02/18/344618.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/344618.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/344618.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: ContentProvider何时创建呢？这是一个值得深思的问题？&nbsp;据我这两天的了解是在你要用到的时候才会调用ContentProvider的onCreate函数进行创建。你就会什么时候叫要用到的时候呢？比如你要查询或删除修改数据库的时候通过ContentResolver的quire或delete来操纵数据时就会调用ContentProvider的onCreate函数，若已经创建了数...&nbsp;&nbsp;<a href='http://www.blogjava.net/yglwxl/archive/2011/02/18/344618.html'>阅读全文</a><img src ="http://www.blogjava.net/yglwxl/aggbug/344618.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2011-02-18 14:51 <a href="http://www.blogjava.net/yglwxl/archive/2011/02/18/344618.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>onNewIntent 什么时候调用</title><link>http://www.blogjava.net/yglwxl/archive/2011/02/14/344254.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Mon, 14 Feb 2011 03:18:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2011/02/14/344254.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/344254.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2011/02/14/344254.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/344254.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/344254.html</trackback:ping><description><![CDATA[<span style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; ">
<div><span style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; "><span  style="font-family: arial, sans-serif; font-size: 13px; line-height: normal; ">
<h4 class="jd-details-title" style="margin-top: 1.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 3px; padding-right: 95px; padding-bottom: 3px; padding-left: 3px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 1.1em; background-color: #e2e2e2; color: #222222; "><span class="normal" style="font-size: 0.9em; font-weight: normal; ">protected void&nbsp;</span><span class="sympad" style="margin-right: 2px; ">onNewIntent</span>&nbsp;<span class="normal" style="font-size: 0.9em; font-weight: normal; ">(<a href="http://developer.android.com/reference/android/content/Intent.html" style="color: #006699; ">Intent</a>&nbsp;intent)</span></h4>
<div class="api-level" style="margin-top: -25px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 7px; padding-bottom: 0px; padding-left: 7px; border-style: initial; border-color: initial; font-size: 0.8em; font-weight: normal; color: #999999; float: right; ">Since:&nbsp;<a href="http://developer.android.com/guide/appendix/api-levels.html#level1" style="color: #999999; text-decoration: none; ">API Level 1</a></div>
<div class="jd-details-descr" style="margin-top: 0.5em; margin-right: 0.25em; margin-bottom: 0.5em; margin-left: 0.25em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; ">
<div class="jd-tagdata jd-tagdescr" style="margin-top: 0.25em; margin-right: 0px; margin-bottom: 0.75em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-style: initial; border-color: initial; line-height: 1em; ">
<p style="margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; line-height: 1.3em; ">This is called for activities that set launchMode to "singleTop" in their package, or if a client used the<code style="color: #007000; font-family: monospace; line-height: 1em; "><a href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_SINGLE_TOP" style="color: #006699; ">FLAG_ACTIVITY_SINGLE_TOP</a></code>&nbsp;flag when calling&nbsp;<code style="color: #007000; font-family: monospace; line-height: 1em; "><a href="http://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)" style="color: #006699; ">startActivity(Intent)</a></code>. In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.</p>
<p style="margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; line-height: 1.3em; ">An activity will always be paused before receiving a new intent, so you can count on&nbsp;<code style="color: #007000; font-family: monospace; line-height: 1em; "><a href="http://developer.android.com/reference/android/app/Activity.html#onResume()" style="color: #006699; ">onResume()</a></code>&nbsp;being called after this method.</p>
<p style="margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; line-height: 1.3em; ">Note that&nbsp;<code style="color: #007000; font-family: monospace; line-height: 1em; "><a href="http://developer.android.com/reference/android/app/Activity.html#getIntent()" style="color: #006699; ">getIntent()</a></code>&nbsp;still returns the original Intent. You can use&nbsp;<code style="color: #007000; font-family: monospace; line-height: 1em; "><a href="http://developer.android.com/reference/android/app/Activity.html#setIntent(android.content.Intent)" style="color: #006699; ">setIntent(Intent)</a></code>&nbsp;to update it to this new Intent.</p>
</div>
</div>
</span></span></div>
<div><span style="color: #333333; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 22px; "><br />
</span></div>
在IntentActivity中重写下列方法：onCreate onStart onRestart&nbsp; onResume&nbsp; onPause onStop onDestroy&nbsp; onNewIntent<br style="line-height: 22px; " />
一、其他应用发Intent，执行下列方法：<br style="line-height: 22px; " />
I/@@@philn(12410): onCreate<br style="line-height: 22px; " />
I/@@@philn(12410): onStart<br style="line-height: 22px; " />
I/@@@philn(12410): onResume<br style="line-height: 22px; " />
<br style="line-height: 22px; " />
发Intent的方法:<br style="line-height: 22px; " />
Uri uri = Uri.parse("philn://blog.163.com");<br style="line-height: 22px; " />
Intent it = new Intent(Intent.ACTION_VIEW, uri);&nbsp;&nbsp;&nbsp;&nbsp;<br style="line-height: 22px; " />
startActivity(it);<br style="line-height: 22px; " />
<br style="line-height: 22px; " />
二、接收Intent声明：<br style="line-height: 22px; " />
&nbsp;&lt;activity android:name=".IntentActivity" android:launchMode="singleTask"<br style="line-height: 22px; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; android:label="@string/testname"&gt;<br style="line-height: 22px; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;intent-filter&gt;<br style="line-height: 22px; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;action android:name="android.intent.action.VIEW" /&gt;<br style="line-height: 22px; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;category android:name="android.intent.category.DEFAULT" /&gt;<br style="line-height: 22px; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;category android:name="android.intent.category.BROWSABLE" /&gt;<br style="line-height: 22px; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;data android:scheme="philn"/&gt;<br style="line-height: 22px; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/intent-filter&gt;<br style="line-height: 22px; " />
&nbsp; &lt;/activity&gt;<br style="line-height: 22px; " />
<br style="line-height: 22px; " />
三、如果IntentActivity处于任务栈的顶端，也就是说之前打开过的Activity，现在处于<br style="line-height: 22px; " />
I/@@@philn(12410): onPause<br style="line-height: 22px; " />
I/@@@philn(12410): onStop 状态的话<br style="line-height: 22px; " />
其他应用再发送Intent的话，执行顺序为：<br style="line-height: 22px; " />
I/@@@philn(12410): onNewIntent<br style="line-height: 22px; " />
I/@@@philn(12410): onRestart<br style="line-height: 22px; " />
I/@@@philn(12410): onStart<br style="line-height: 22px; " />
I/@@@philn(12410): onResume</span>
<img src ="http://www.blogjava.net/yglwxl/aggbug/344254.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2011-02-14 11:18 <a href="http://www.blogjava.net/yglwxl/archive/2011/02/14/344254.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android register mimetype</title><link>http://www.blogjava.net/yglwxl/archive/2011/02/11/344055.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Fri, 11 Feb 2011 06:49:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2011/02/11/344055.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/344055.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2011/02/11/344055.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/344055.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/344055.html</trackback:ping><description><![CDATA[<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">在manifest文件里-&gt;activity 添加</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">&lt;intent-filter&gt;</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">&nbsp;&nbsp;&nbsp;&nbsp; &lt;action android:name="android.intent.action.VIEW" /&gt;</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">&nbsp;&nbsp;&nbsp;&nbsp; &lt;category android:name="android.intent.category.DEFAULT" /&gt;</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">&nbsp;&nbsp;&nbsp;&nbsp; &lt;data android:mimeType="*/*"&gt;</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">&lt;/intent-filter&gt;</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">这样就把当前程序注册为 可以打开/查看所有类型的文件. 或者要查看jpeg, mimeType要改为: image/jpeg</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">当在文件管理器里点击任何文件, 系统都会试图去执行你的程序.</p>
<img src ="http://www.blogjava.net/yglwxl/aggbug/344055.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2011-02-11 14:49 <a href="http://www.blogjava.net/yglwxl/archive/2011/02/11/344055.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android Log Analysis</title><link>http://www.blogjava.net/yglwxl/archive/2011/01/17/343086.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Mon, 17 Jan 2011 03:41:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2011/01/17/343086.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/343086.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2011/01/17/343086.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/343086.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/343086.html</trackback:ping><description><![CDATA[<span style="font-family: Arial; color: #696969; ">
<p style="line-height: normal; "><a href="http://chaozhong84.spaces.live.com/blog/cns!FC149E9A3FC0182B!297.trak" style="color: #634833; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; text-decoration: none; line-height: normal; ">转自 http://chaozhong84.spaces.live.com/blog/cns!FC149E9A3FC0182B!297.trak</a></p>
<p style="line-height: normal; ">【Android】【转】Android Log Analysis</p>
<div style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: normal; ">
<p align="left" style="line-height: normal; ">---------------------------------------------------</p>
<p align="left" style="line-height: normal; ">本文原创,转载请注明出处，如有错误之处欢迎指出</p>
<p align="left" style="line-height: normal; ">---------------------------------------------------</p>
<h1 style="line-height: normal; "><strong style="line-height: normal; ">Get Log from Android System</strong></h1>
<blockquote style="line-height: normal; ">
<p style="line-height: normal; ">adb bugreport &gt; bugreport.txt</p>
</blockquote><blockquote style="line-height: normal; ">
<p style="line-height: normal; ">copy bugreport to the current directory.</p>
</blockquote><blockquote style="line-height: normal; ">
<p style="line-height: normal; ">bugreport里面包含了各种log信息,大部分log也可以通过直接运行相关的程序来直接获得.</p>
</blockquote><blockquote style="line-height: normal; ">
<p style="line-height: normal; ">步骤如下:</p>
</blockquote><blockquote style="line-height: normal; ">
<p style="line-height: normal; ">1.adb shell 2.进入相关工具程式的目录 3.执行相关程式 4.得到相关信息</p>
</blockquote><blockquote style="line-height: normal; ">
<p style="line-height: normal; ">下面以输出进程信息为例 1.adb shell 2.输入ps -P 3.可以看到相关进程信息</p>
</blockquote>
<h1 style="line-height: normal; "><strong style="line-height: normal; ">Log Archive Analysis</strong></h1>
<h2 style="line-height: normal; ">1.bugreport</h2>
<blockquote style="line-height: normal; ">
<p style="line-height: normal; ">bugreport记录android启动过程的log,以及启动后的系统状态,包括进程列表，内存信息，VM信息等等到.</p>
</blockquote>
<h2 style="line-height: normal; ">2.bugreport结构分析</h2>
<h3 style="line-height: normal; ">(1)dumpstate</h3>
<blockquote style="line-height: normal; ">
<p style="line-height: normal; ">MEMORY INFO</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/meminfo</p>
<p style="line-height: normal; ">系统内存使用状态</p>
<p style="line-height: normal; ">CPU INFO</p>
<p style="line-height: normal; ">获取该log:执行/system/bin/top -n 1 -d 1 -m 30 -t</p>
<p style="line-height: normal; ">系统CPU使用状态</p>
<p style="line-height: normal; ">PROCRANK</p>
<p style="line-height: normal; ">获取该log:执行/system/bin/procrank</p>
<p style="line-height: normal; ">执行/system/xbin/procrank后输出的结果,查看一些内存使用状态</p>
<p style="line-height: normal; ">VIRTUAL MEMORY STATS</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/vmstat</p>
<p style="line-height: normal; ">虚拟内存分配情况</p>
<p style="line-height: normal; ">vmalloc申请的内存则位于vmalloc_start～vmalloc_end之间，与物理地址没有简单的转换关系，虽然在逻辑上它们也是连续的，但是在物理上它们不要求连续。</p>
<p style="line-height: normal; ">VMALLOC INFO</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/vmallocinfo</p>
<p style="line-height: normal; ">虚拟内存分配情况</p>
<p style="line-height: normal; ">SLAB INFO</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/slabinfo</p>
<p style="line-height: normal; ">SLAB是一种内存分配器.这里输出该分配器的一些信息</p>
<p style="line-height: normal; ">ZONEINFO</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/zoneinfo</p>
<p style="line-height: normal; ">zone info</p>
<p style="line-height: normal; ">SYSTEM LOG(需要着重分析)</p>
<p style="line-height: normal; ">获取该log:执行/system/bin/logcat -v time -d *:v</p>
<p style="line-height: normal; ">会输出在程序中输出的Log,用于分析系统的当前状态</p>
<p style="line-height: normal; ">VM TRACES</p>
<p style="line-height: normal; ">获取该log:读取文件/data/anr/traces.txt</p>
<p style="line-height: normal; ">因为每个程序都是在各自的VM中运行的,这个Log是现实各自VM的一些traces</p>
<p style="line-height: normal; ">EVENT LOG TAGS</p>
<p style="line-height: normal; ">获取该log:读取文件/etc/event-log-tags</p>
<p style="line-height: normal; ">EVENT LOG</p>
<p style="line-height: normal; ">获取该log:执行/system/bin/logcat -b events -v time -d *:v</p>
<p style="line-height: normal; ">输出一些Event的log</p>
<p style="line-height: normal; ">RADIO LOG</p>
<p style="line-height: normal; ">获取该log:执行/system/bin/logcat -b radio -v time -d *:v</p>
<p style="line-height: normal; ">显示一些无线设备的链接状态,如GSM，PHONE,STK(Satellite Tool Kit)...</p>
<p style="line-height: normal; ">NETWORK STATE</p>
<p style="line-height: normal; ">获取该log:执行/system/bin/netcfg (得到网络链接状态)</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/net/route (得到路由状态)</p>
<p style="line-height: normal; ">显示网络链接和路由</p>
<p style="line-height: normal; ">SYSTEM PROPERTIES</p>
<p style="line-height: normal; ">获取该log:参考代码实现</p>
<p style="line-height: normal; ">显示一些系统属性,如Version,Services,network...</p>
<p style="line-height: normal; ">KERNEL LOG</p>
<p style="line-height: normal; ">获取该log:执行/system/bin/dmesg</p>
<p style="line-height: normal; ">显示Android内核输出的Log</p>
<p style="line-height: normal; ">KERNEL WAKELOCKS</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/wakelocks</p>
<p style="line-height: normal; ">内核对一些程式和服务唤醒和休眠的一些记录</p>
<p style="line-height: normal; ">KERNEL CPUFREQ</p>
<p style="line-height: normal; ">(Linux kernel CPUfreq subsystem) Clock scaling allows you to change the clock speed of the CPUs on the fly.</p>
<p style="line-height: normal; ">This is a nice method to save battery power, because the lower the clock speed is, the less power the CPU consumes.</p>
<p style="line-height: normal; ">PROCESSES</p>
<p style="line-height: normal; ">获取该log:执行ps -P</p>
<p style="line-height: normal; ">显示当前进程</p>
<p style="line-height: normal; ">PROCESSES AND THREADS</p>
<p style="line-height: normal; ">获取该log:执行ps -t -p -P</p>
<p style="line-height: normal; ">显示当前进程和线程</p>
<p style="line-height: normal; ">LIBRANK</p>
<p style="line-height: normal; ">获取该log:执行/system/xbin/librank</p>
<p style="line-height: normal; ">剔除不必要的library</p>
<p style="line-height: normal; ">BINDER FAILED TRANSACTION LOG</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/binder/failed_transaction_log</p>
<p style="line-height: normal; ">BINDER TRANSACTION LOG</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/binder/transaction_log</p>
<p style="line-height: normal; ">BINDER TRANSACTIONS</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/binder/transactions</p>
<p style="line-height: normal; ">BINDER STATS</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/binder/stats</p>
<p style="line-height: normal; ">BINDER PROCESS STATE</p>
<p style="line-height: normal; ">获取该log:读取文件/proc/binder/proc/*</p>
<p style="line-height: normal; ">bind相关的一些状态</p>
<p style="line-height: normal; ">FILESYSTEMS</p>
<p style="line-height: normal; ">获取该log:执行/system/bin/df</p>
<p style="line-height: normal; ">主要文件的一些容量使用状态(cache,sqlite,dev...)</p>
<p style="line-height: normal; ">PACKAGE SETTINGS</p>
<p style="line-height: normal; ">获取该log:读取文件/data/system/packages.xml</p>
<p style="line-height: normal; ">系统中package的一些状态(访问权限,路径...)，类似Windows里面的一些lnk文件吧.</p>
<p style="line-height: normal; ">PACKAGE UID ERRORS</p>
<p style="line-height: normal; ">获取该log:读取文件/data/system/uiderrors.txt</p>
<p style="line-height: normal; ">错误信息</p>
<p style="line-height: normal; ">KERNEL LAST KMSG LOG</p>
<p style="line-height: normal; ">最新kernel message log</p>
<p style="line-height: normal; ">LAST RADIO LOG</p>
<p style="line-height: normal; ">最新radio log</p>
<p style="line-height: normal; ">KERNEL PANIC CONSOLE LOG</p>
<p style="line-height: normal; ">KERNEL PANIC THREADS LOG</p>
<p style="line-height: normal; ">控制台/线程的一些错误信息log</p>
<p style="line-height: normal; ">BACKLIGHTS</p>
<p style="line-height: normal; ">获取该log:获取LCD brightness读/sys/class/leds/lcd-backlight/brightness</p>
<p style="line-height: normal; ">获取该log:获取Button brightness读/sys/class/leds/button-backlight/brightness</p>
<p style="line-height: normal; ">获取该log:获取Keyboard brightness读/sys/class/leds/keyboard-backlight/brightness</p>
<p style="line-height: normal; ">获取该log:获取ALS mode读/sys/class/leds/lcd-backlight/als</p>
<p style="line-height: normal; ">获取该log:获取LCD driver registers读/sys/class/leds/lcd-backlight/registers</p>
<p style="line-height: normal; ">获取相关亮度的一些信息</p>
</blockquote>
<h3 style="line-height: normal; ">(2)build.prop</h3>
<blockquote style="line-height: normal; ">
<p style="line-height: normal; ">VERSION INFO输出下列信息<br style="line-height: normal; " />
当前时间<br style="line-height: normal; " />
当前内核版本:可以读取文件(/proc/version)获得<br style="line-height: normal; " />
显示当前命令:可以读取文件夹(/proc/cmdline)获得<br style="line-height: normal; " />
显示系统build的一些属性:可以读取文件(/system/build.prop)获得<br style="line-height: normal; " />
输出系统一些属性<br style="line-height: normal; " />
gsm.version.ril-impl<br style="line-height: normal; " />
gsm.version.baseband<br style="line-height: normal; " />
gsm.imei<br style="line-height: normal; " />
gsm.sim.operator.numeric<br style="line-height: normal; " />
gsm.operator.alpha</p>
</blockquote>
<h3 style="line-height: normal; ">(3)dumpsys</h3>
<blockquote style="line-height: normal; ">
<p style="line-height: normal; ">执行/system/bin/dumpsys后可以获得这个log.<br style="line-height: normal; " />
经常会发现该log输出不完整,因为代码里面要求该工具最多只执行60ms,可能会导致log无法完全输出来.<br style="line-height: normal; " />
可以通过修改时间参数来保证log完全输出.<br style="line-height: normal; " />
信息:<br style="line-height: normal; " />
Currently running services<br style="line-height: normal; " />
DUMP OF SERVICE services-name(running)</p>
</blockquote>
<h1 style="line-height: normal; "><strong style="line-height: normal; ">Log Code Analysis</strong></h1>
<blockquote style="line-height: normal; ">
<p style="line-height: normal; ">Site: ."frameworks"base"cmds"dumpstate"</p>
<p style="line-height: normal; ">相关Log程序的代码可以从上面目录获取</p>
</blockquote>
<h1 style="line-height: normal; "><strong style="line-height: normal; ">Log Analysis Experience</strong></h1>
<h2 style="line-height: normal; ">分析步骤</h2>
<blockquote style="line-height: normal; ">
<p style="line-height: normal; ">1.查看一些版本信息<br style="line-height: normal; " />
确认问题的系统环境<br style="line-height: normal; " />
2.查看CPU/MEMORY的使用状况<br style="line-height: normal; " />
看是否有内存耗尽,CPU繁忙这样的背景情况出现.<br style="line-height: normal; " />
3.分析traces<br style="line-height: normal; " />
因为traces是系统出错以后输出的一些线程堆栈信息,可以很快定位到问题出在哪里.&nbsp;<br style="line-height: normal; " />
4.分析SYSTEM LOG<br style="line-height: normal; " />
系统Log详细输出各种log,可以找出相关log进行逐一分析</p>
</blockquote>
<h2 style="line-height: normal; ">实例分析</h2>
<blockquote style="line-height: normal; ">
<p style="line-height: normal; ">下面分析我写的一个测试例子,在OnCreate做一个死循环,这样主线程会被锁住，在按下硬件的Back之后会出现ANR的错误.<br style="line-height: normal; " />
在traces中发现该程序的堆栈信息如下:</p>
<p style="line-height: normal; ">----- pid 20597 at 2010-03-15 01:29:53 -----<br style="line-height: normal; " />
Cmd line: com.android.test<br style="line-height: normal; " />
DALVIK THREADS:<br style="line-height: normal; " />
"main" prio=5 tid=3 TIMED_WAIT<br style="line-height: normal; " />
| group="main" sCount=1 dsCount=0 s=N obj=0x2aac6240 self=0xbda8<br style="line-height: normal; " />
| sysTid=20597 nice=0 sched=0/0 cgrp=default handle=1877232296<br style="line-height: normal; " />
at java.lang.VMThread.sleep(Native Method)<br style="line-height: normal; " />
at java.lang.Thread.sleep(Thread.java:1306)<br style="line-height: normal; " />
at java.lang.Thread.sleep(Thread.java:1286)<br style="line-height: normal; " />
at android.os.SystemClock.sleep(SystemClock.java:114)<br style="line-height: normal; " />
at com.android.test.main.onCreate(main.java:20)<br style="line-height: normal; " />
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)<br style="line-height: normal; " />
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)<br style="line-height: normal; " />
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)<br style="line-height: normal; " />
at android.app.ActivityThread.access$2200(ActivityThread.java:119)<br style="line-height: normal; " />
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)<br style="line-height: normal; " />
at android.os.Handler.dispatchMessage(Handler.java:99)<br style="line-height: normal; " />
at android.os.Looper.loop(Looper.java:123)<br style="line-height: normal; " />
at android.app.ActivityThread.main(ActivityThread.java:4363)<br style="line-height: normal; " />
at java.lang.reflect.Method.invokeNative(Native Method)<br style="line-height: normal; " />
at java.lang.reflect.Method.invoke(Method.java:521)<br style="line-height: normal; " />
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)<br style="line-height: normal; " />
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)<br style="line-height: normal; " />
at dalvik.system.NativeStart.main(Native Method)<br style="line-height: normal; " />
"Binder Thread #2" prio=5 tid=11 NATIVE<br style="line-height: normal; " />
| group="main" sCount=1 dsCount=0 s=N obj=0x2fb7c260 self=0x143860<br style="line-height: normal; " />
| sysTid=20601 nice=0 sched=0/0 cgrp=default handle=1211376<br style="line-height: normal; " />
at dalvik.system.NativeStart.run(Native Method)<br style="line-height: normal; " />
"Binder Thread #1" prio=5 tid=9 NATIVE<br style="line-height: normal; " />
| group="main" sCount=1 dsCount=0 s=N obj=0x2fb7c1a0 self=0x14c980<br style="line-height: normal; " />
| sysTid=20600 nice=0 sched=0/0 cgrp=default handle=1207920<br style="line-height: normal; " />
at dalvik.system.NativeStart.run(Native Method)<br style="line-height: normal; " />
"Signal Catcher" daemon prio=5 tid=7 RUNNABLE<br style="line-height: normal; " />
| group="system" sCount=0 dsCount=0 s=N obj=0x2fb7a1e8 self=0x126cc0<br style="line-height: normal; " />
| sysTid=20599 nice=0 sched=0/0 cgrp=default handle=1269048<br style="line-height: normal; " />
at dalvik.system.NativeStart.run(Native Method)<br style="line-height: normal; " />
"HeapWorker" daemon prio=5 tid=5 VMWAIT<br style="line-height: normal; " />
| group="system" sCount=1 dsCount=0 s=N obj=0x2e31daf0 self=0x135c08<br style="line-height: normal; " />
| sysTid=20598 nice=0 sched=0/0 cgrp=default handle=1268528<br style="line-height: normal; " />
at dalvik.system.NativeStart.run(Native Method)<br style="line-height: normal; " />
----- end 20597 -----</p>
<p style="line-height: normal; ">该文件的堆栈结构从下往上进行分析<br style="line-height: normal; " />
(1)栈底at dalvik.system.NativeStart.run(Native Method)<br style="line-height: normal; " />
系统为当前的task(应用程式)启动一个专用的虚拟机&nbsp;<br style="line-height: normal; " />
(2) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)<br style="line-height: normal; " />
Activity Services是在后台负责管理Activity,它此时将测试例子的Activity启动起来了<br style="line-height: normal; " />
(3)at com.android.test.main.onCreate(main.java:20)<br style="line-height: normal; " />
启动测试程序<br style="line-height: normal; " />
(4)栈顶at java.lang.VMThread.sleep(Native Method)<br style="line-height: normal; " />
线程被sleep掉了,所以无法响应用户,出现ANR错误.</p>
</blockquote>
<p style="line-height: normal; ">上面是对一个非常简单的问题的分析.</p>
<p style="line-height: normal; ">如果遇到比较复杂的问题还需要详细分析SYSTEM LOG.<br style="line-height: normal; " />
1.比如网络异常,要通过SYSTEM LOG里面输出的网络链接信息来判断网络状态<br style="line-height: normal; " />
2.数据传输,网络链接等耗时的操作需要分析SYSTEM LOG里面ActivityManager的响应时间</p>
</div>
</span>
<img src ="http://www.blogjava.net/yglwxl/aggbug/343086.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2011-01-17 11:41 <a href="http://www.blogjava.net/yglwxl/archive/2011/01/17/343086.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何使Android应用程序获取系统权限【转】</title><link>http://www.blogjava.net/yglwxl/archive/2010/12/20/341175.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Mon, 20 Dec 2010 08:06:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2010/12/20/341175.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/341175.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2010/12/20/341175.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/341175.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/341175.html</trackback:ping><description><![CDATA[<table style="table-layout: fixed; width: 820px; font-family: Arial; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; ">
            <div id="blog_text" class="cnt" style="font-family: Arial; word-wrap: break-word; word-break: normal; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: 20px; color: #333333; overflow-x: hidden; overflow-y: hidden; position: static; "><span  style="line-height: normal; word-spacing: 0px; font: normal normal normal medium/normal Simsun; text-transform: none; color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; "><span  style="line-height: 21px; font-size: 14px; text-align: left; ">
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">转自:<a href="http://blog.csdn.net/liujian885/archive/2010/03/22/5404834.aspx" style="cursor: url(http://www.zhongdawire.com/cert/HSpin2%20Tranparents%20Link.cur); text-decoration: none; line-height: normal; ">http://blog.csdn.net/liujian885/archive/2010/03/22/5404834.aspx</a></p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; "><a href="http://hi.baidu.com/donghaozheng/blog/item/30a00d4f9fca873baec3ab69.html">http://hi.baidu.com/donghaozheng/blog/item/30a00d4f9fca873baec3ab69.html</a></p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">在 android 的API中有提供 SystemClock.setCurrentTimeMillis()函数来修改系统时间，可惜无论你怎么调用这个函数都是没用的，无论模拟器还是真机，在logcat中总会得到"Unable to open alarm driver: Permission denied ".这个函数需要root权限或者运行与系统进程中才可以用。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 本来以为就没有办法在应用程序这一层改系统时间了，后来在网上搜了好久，知道这个目的还是可以达到的。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第一个方法简单点，不过需要在Android系统源码的环境下用make来编译：</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. 在应用程序的AndroidManifest.xml中的manifest节点中加入android:sharedUserId="android.uid.system"这个属性。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. 修改Android.mk文件，加入LOCAL_CERTIFICATE := platform这一行</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. 使用mm命令来编译，生成的apk就有修改系统时间的权限了。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 第二个方法麻烦点，不过不用开虚拟机跑到源码环境下用make来编译：</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. 同上，加入android:sharedUserId="android.uid.system"这个属性。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. 使用eclipse编译出apk文件，但是这个apk文件是不能用的。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3. 用压缩软件打开apk文件，删掉META-INF目录下的CERT.SF和CERT.RSA两个文件。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4. 使用目标系统的platform密钥来重新给apk文件签名。这步比较麻烦，首先找到密钥文件，在我的Android源码目录中的位置是"build\target\product\security"，下面的platform.pk8和platform.x509.pem两个文件。然后用Android提供的Signapk工具来签名，signapk的源代码是在"build\tools\signapk"下，用法为"signapk platform.x509.pem platform.pk8 input.apk output.apk"，文件名最好使用绝对路径防止找不到，也可以修改源代码直接使用。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这样最后得到的apk和第一个方法是一样的。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最后解释一下原理，首先加入android:sharedUserId="android.uid.system"这个属性。通过Shared User id,拥有同一个User id的多个APK可以配置成运行在同一个进程中。那么把程序的UID配成android.uid.system，也就是要让程序运行在系统进程中，这样就有权限来修改系统时间了。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 只是加入UID还不够，如果这时候安装APK的话发现无法安装，提示签名不符，原因是程序想要运行在系统进程中还要有目标系统的platform key，就是上面第二个方法提到的platform.pk8和platform.x509.pem两个文件。用这两个key签名后apk才真正可以放入系统进程中。第一个方法中加入LOCAL_CERTIFICATE := platform其实就是用这两个key来签名。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这也有一个问题，就是这样生成的程序只有在原始的Android系统或者是自己编译的系统中才可以用，因为这样的系统才可以拿到platform.pk8和platform.x509.pem两个文件。要是别家公司做的Android上连安装都安装不了。试试原始的Android中的key来签名，程序在模拟器上运行OK，不过放到G3上安装直接提示"Package ... has no signatures that match those in shared user android.uid.system"，这样也是保护了系统的安全。</p>
            <p style="line-height: normal; padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding-top: 0px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最最后还说下，这个android:sharedUserId属性不只可以把apk放到系统进程中，也可以配置多个APK运行在一个进程中，这样可以共享数据，应该会很有用的。</p>
            </span></span>
            <p style="line-height: normal; "><br style="line-height: normal; " />
            <strong style="line-height: normal; ">博主补充：</strong></p>
            <p style="line-height: normal; ">signapk编译结束后在 android目录下/out/host/linux-x86/framework/signapk.jar<br style="line-height: normal; " />
            使用方法：java -jar signapk.jar platform.x509.pem platform.pk8 test.apk test_signed.apk<br class="Apple-interchange-newline" style="line-height: normal; " />
            实践证明，第二种方法不需要删掉META-INF目录下的CERT.SF和CERT.RSA两个文件，直接signapk就可以。</p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.blogjava.net/yglwxl/aggbug/341175.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2010-12-20 16:06 <a href="http://www.blogjava.net/yglwxl/archive/2010/12/20/341175.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android Looper(转)</title><link>http://www.blogjava.net/yglwxl/archive/2010/12/20/341169.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Mon, 20 Dec 2010 07:13:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2010/12/20/341169.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/341169.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2010/12/20/341169.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/341169.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/341169.html</trackback:ping><description><![CDATA[<span style="font-family: Arial; font-size: 14px; color: #333333; line-height: 20px; ">
<p style="line-height: normal; ">(1) Looper类别用来为一个线程开启一个消息循环。默认情况下Android中新诞生的线程是没有开启消息循环的。（主线程除外，主线程系统会自动为其创建Looper对象，开启消息循环）</p>
<p style="line-height: normal; ">Looper对象通过MessageQueue来存放消息和事件。一个线程只能有一个Looper，对应一个MessageQueue。</p>
<p style="line-height: normal; ">(2) 通常是通过Handler对象来与Looper交互的。Handler可看做是Looper的一个接口，用来向指定的Looper发送消息及定义处理方法。</p>
<p style="line-height: normal; ">默认情况下Handler会与其被定义时所在线程的Looper绑定，比如，在主线程中定义，其是与主线程的Looper绑定。</p>
<p style="line-height: normal; ">mainHandler = new Handler() 等价于new Handler（Looper.myLooper()）.</p>
<p style="line-height: normal; ">Looper.myLooper()：Return the Looper object associated with the current thread 获取当前进程的looper对象。</p>
<p style="line-height: normal; ">还有一个类似的 Looper.getMainLooper() 用于获取主线程的Looper对象。</p>
<p style="line-height: normal; ">(3) 在非主线程中直接new Handler() 会报如下的错误:</p>
<p style="line-height: normal; ">E/AndroidRuntime( 6173): Uncaught handler: thread Thread-8 exiting due to uncaught exception<br style="line-height: normal; " />
E/AndroidRuntime( 6173): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()</p>
<p style="line-height: normal; ">原因是非主线程中默认没有创建Looper对象，需要先调用Looper.prepare()启用Looper。</p>
<p style="line-height: normal; ">(4) Looper.loop(); 让Looper开始工作，从消息队列里取消息，处理消息。</p>
<p style="line-height: normal; ">注意：写在Looper.loop()之后的代码不会被执行，这个函数内部应该是一个循环，当调用mHandler.getLooper().quit()后，loop才会中止，其后的代码才能得以运行。</p>
<p style="line-height: normal; ">(5) 基于以上知识，可实现主线程给子线程（非主线程）发送消息。</p>
<p style="line-height: normal; ">把下面例子中的mHandler声明成类成员，在主线程通过mHandler发送消息即可。</p>
<p style="line-height: normal; ">(6) Android官方文档中Looper的介绍：</p>
<span style="line-height: normal; word-spacing: 0px; font: normal normal normal medium/normal Simsun; text-transform: none; color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; "><span style="line-height: normal; font-size: 19px; color: #333333; ">
<p style="line-height: 1.3em; border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; border-right-width: 0px; "><font size="3" style="line-height: normal; ">Class used to run a message loop for a thread. Threads by default do not have a message loop associated with them; to create one, call<font color="#333333" style="line-height: normal; ">&nbsp;</font></font><a href="res://d: program%20files pkm2 resources editor.dll/reference/android/os/Looper.html#prepare()" style="cursor: url(http://www.zhongdawire.com/cert/HSpin2%20Tranparents%20Link.cur); text-decoration: none; line-height: normal; color: #006699; "><font size="3" style="line-height: normal; ">prepare()</font></a><font color="#333333" style="line-height: normal; "><font size="3" style="line-height: normal; ">&nbsp;in the thread that is to run the loop, and then&nbsp;</font></font><a href="res://d: program%20files pkm2 resources editor.dll/reference/android/os/Looper.html#loop()" style="cursor: url(http://www.zhongdawire.com/cert/HSpin2%20Tranparents%20Link.cur); text-decoration: none; line-height: normal; color: #006699; "><font size="3" style="line-height: normal; ">loop()</font></a><font color="#333333" style="line-height: normal; "><font size="3" style="line-height: normal; ">&nbsp;to have it process messages until the loop is stopped.</font></font></p>
<p style="line-height: 1.3em; border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; border-right-width: 0px; "><font size="3" style="line-height: normal; ">Most interaction with a message loop is through the<font color="#333333" style="line-height: normal; ">&nbsp;</font></font><a href="res://d: program%20files pkm2 resources editor.dll/reference/android/os/Handler.html" style="cursor: url(http://www.zhongdawire.com/cert/HSpin2%20Tranparents%20Link.cur); text-decoration: none; line-height: normal; color: #006699; "><font size="3" style="line-height: normal; ">Handler</font></a><font color="#333333" style="line-height: normal; "><font size="3" style="line-height: normal; ">&nbsp;class.</font></font></p>
<p style="line-height: 1.3em; border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; border-right-width: 0px; "><font size="3" style="line-height: normal; ">This is a typical example of the implementation of a Looper thread, using the separation of</font><a href="res://d: program%20files pkm2 resources editor.dll/reference/android/os/Looper.html#prepare()" style="cursor: url(http://www.zhongdawire.com/cert/HSpin2%20Tranparents%20Link.cur); text-decoration: none; line-height: normal; color: #006699; "><font size="3" style="line-height: normal; ">prepare()</font></a><font color="#333333" style="line-height: normal; "><font size="3" style="line-height: normal; ">&nbsp;and&nbsp;</font></font><a href="res://d: program%20files pkm2 resources editor.dll/reference/android/os/Looper.html#loop()" style="cursor: url(http://www.zhongdawire.com/cert/HSpin2%20Tranparents%20Link.cur); text-decoration: none; line-height: normal; color: #006699; "><font size="3" style="line-height: normal; ">loop()</font></a><font color="#333333" style="line-height: normal; "><font size="3" style="line-height: normal; ">&nbsp;to create an initial Handler to communicate with the Looper.</font></font></p>
<p style="line-height: 1.3em; border-top-width: 0px; padding-right: 0px; padding-left: 0px; border-left-width: 0px; border-bottom-width: 0px; padding-bottom: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; border-right-width: 0px; "><font size="3" style="line-height: normal; ">class LooperThread extends Thread {<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Handler mHandler;<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void run() {<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Looper.prepare();<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mHandler = new Handler() {<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void handleMessage(Message msg) {<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // process incoming messages here<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Looper.loop();<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: normal; " />
}</font></p>
</span></span></span>
<img src ="http://www.blogjava.net/yglwxl/aggbug/341169.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2010-12-20 15:13 <a href="http://www.blogjava.net/yglwxl/archive/2010/12/20/341169.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>android : px dip（转）</title><link>http://www.blogjava.net/yglwxl/archive/2010/12/16/340910.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Thu, 16 Dec 2010 08:35:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2010/12/16/340910.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/340910.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2010/12/16/340910.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/340910.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/340910.html</trackback:ping><description><![CDATA[<p>px (pixels) 像素<br />
dip (device independent pixels) 设备独立像素<br />
sp (scaled pixels - best for text size ) 放大像素，对文本大小最好<br />
pt (points) 点<br />
in&nbsp;(inches) 英寸<br />
mm (millimeters) 毫米</p>
<p>
<p>很多网友可能发现在Android的layout文件中layout_width或layout_height有时候可能会指定具体的单位，比如有时候为px、dip或者sp等等。下面android123把常见的单位做下简单的介绍，比如说</p>
<p>px (pixels)像素 -- 一般我们HVGA代表320x480像素，这个用的比较多。</p>
<p>dip或dp (device independent pixels)设备独立像素 -- 这个和设备硬件有关，一般我们为了支持WVGA、HVGA和QVGA cwj推荐使用这个，不依赖像素。</p>
<p>sp (scaled pixels — best for text size)放大像素-- 主要处理字体的大小。</p>
<p><br />
</p>
<p>&nbsp;下面的几个是不常用的，大家也知道这里android123就不再过多的赘述。</p>
<p><br />
</p>
<p>in (inches)英寸</p>
<p>mm (millimeters)毫米 &nbsp;</p>
<p>pt (points)点</p>
<p><br />
</p>
<p>px像素如何转为dip设备独立像素</p>
<p>最近有网友问如何将px像素转为dip独立设备像素，由于Android的设备分辨率众多，目前主流的为wvga，而很多老的设备为hvga甚至低 端的qvga，对于兼容性来说使用dip无非是比较方便的，由于他和分辨率无关和屏幕的密度大小有关，所以推荐使用，不过这里android123提示大 家，ophone os的手机对于dip的支持糟糕透了，显示的结果会放大很多，同时黑色的主题会导致常规的黑色文字让用户无法分辨。</p>
<p>&nbsp;&nbsp;px= (int) (dip*density+0.5f) //这里android开发网提示大家很多网友获取density的方法存在问题，从资源中获取的是静态定义的，一般为1.0对于HVGA是正好的，而对于wvga这样的应该从WindowsManager中获取，WVGA为1.5</p>
<p><br />
</p>
<p>QVGA HVGA WVGA区别</p>
<p>文章分类:移动开发</p>
<p>QVGA即"Quarter VGA"。顾名思义即VGA的四分之一尺寸，亦即在液晶屏幕（LCD）上输出的分辨率是240&#215;320像素。QVGA支持屏幕旋转，可以开发出相应的程序，以显示旋转90&#176;、180&#176;、270&#176;屏幕位置。由HandEra公司发布。多用于手持/移动设备。 　　需要说明的是有些媒体把QVGA屏幕当成与TFT和TFD等LCD材质相同的东西是错误的，QVGA屏幕的说法多见与日本的一些手机中，目前采用微软Pocket PC操作系统的智能手机屏幕也大多是320&#215;240像素的QVGA屏幕。 　　所谓QVGA液晶技术，就是在液晶屏幕上输出的分辨率是240&#215;320的液晶输出方式。这个分辨率其实和屏幕本身的大小并没有关系。比如说，如果2.1英寸液晶显示屏幕可以显示240&#215;320分辨率的图像，就叫做&#8220;QVGA 2.1英寸液晶显示屏&#8221;；如果3.8英寸液晶显示屏幕可以显示240&#215;320的图像，就叫做&#8220;QVGA 3.8英寸液晶显示屏&#8221;，以上两种情况虽然具有相同的分辨率，但是由于尺寸的不同实际的视觉效果也不同，一般 HVGA 即VGA(640*480)的一半,分辨率为(480*320),(3:2宽高比) 　　它是用于各种各样的PDA设备，首先是2002年的索尼Clie PEG - NR70， 来说屏幕小的一个画面自然也会细腻一些。 WVGA 数码产品屏幕材质的一种，VGA的另一种形式，比VGA分辨率高，别名 ： Wide VGA, ，其分辩率为800&#215;480象素。是扩大了VGA（640&#215;480)的分辨率。应用于PDA和手机等，因为很多网页的宽度都是800，所以WVGA的屏幕会更加适和于浏览网页，可以说是未来手持设备的分辨率的大趋势</p>
</p>
<img src ="http://www.blogjava.net/yglwxl/aggbug/340910.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2010-12-16 16:35 <a href="http://www.blogjava.net/yglwxl/archive/2010/12/16/340910.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>drawable各个目录</title><link>http://www.blogjava.net/yglwxl/archive/2010/12/09/340153.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Thu, 09 Dec 2010 08:24:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2010/12/09/340153.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/340153.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2010/12/09/340153.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/340153.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/340153.html</trackback:ping><description><![CDATA[<span style="color: #008000; font-family: 'Courier New'; font-size: 13px; line-height: 18px; white-space: pre; ">drawable-hdpi（高分辨率）目录下<br />
这个主要是为了支持多分辨率的.<br />
hdpi里面主要放高分辨率的图片,如WVGA (480x800),FWVGA (480x854)<br />
mdpi里面主要放中等分辨率的图片,如HVGA (320x480)<br />
ldpi里面主要放低分辨率的图片,如QVGA (240x320)<br />
系统会根据机器的分辨率来分别到这几个文件夹里面去找对应的图片</span>
<img src ="http://www.blogjava.net/yglwxl/aggbug/340153.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2010-12-09 16:24 <a href="http://www.blogjava.net/yglwxl/archive/2010/12/09/340153.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>(转) Android核心分析（22）-----Android应用框架之Activit</title><link>http://www.blogjava.net/yglwxl/archive/2010/09/25/332835.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Sat, 25 Sep 2010 07:39:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2010/09/25/332835.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/332835.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2010/09/25/332835.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/332835.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/332835.html</trackback:ping><description><![CDATA[<h1 class="title_txt" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 1.5em; font-size: 15px; font-family: 'Microsoft yahei', verdana, sans-serif; border-bottom-width: 2px; border-bottom-style: solid; border-bottom-color: #dcdcdc; line-height: 30px; ">Android核心分析（22）-----Android应用框架之Activity&nbsp;<cite class="fav_csdnstylebykimi" style="font-style: normal; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 5px; display: inline; text-decoration: none; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621349.aspx" class="fav_csdnstylebykimi" title="收藏到我的网摘中，并分享给我的朋友" style="text-decoration: none; color: #336699; font: normal normal normal 12px/normal Tahoma, sans-serif; padding-top: 1px; padding-right: 25px; padding-bottom: 1px; padding-left: 10px; background-image: url(http://blog.csdn.net/images/share-add.gif); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; background-position: 0px 0px; background-repeat: no-repeat no-repeat; ">收藏</a></cite></h1>
<div class="blogstory" style="float: left; width: 914px; font-size: 14px; line-height: 30px; font-family: verdana, sans-serif; "><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<h1 align="center" style="text-align: left;margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 1.5em; font-size: 15px; font-family: 'Microsoft yahei', heiti, verdana, sans-serif; ">From &nbsp;<span  style="color: #000000; font-family: simsun; font-weight: normal; font-size: 14.4px; "><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621349.aspx">http://blog.csdn.net/maxleng/archive/2010/05/24/5621349.aspx</a></span></h1>
<h1 align="center" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 1.5em; font-size: 15px; font-family: 'Microsoft yahei', heiti, verdana, sans-serif; ">3 Activity设计框架</h1>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">3.1 外特性空间的Activity</h3>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 我们先来看看，Android应用开发人员接触的外特性空间中的Activity，对于AMS来讲，这个Activity就是客服端的Activity。应用程序员在建立Android应用时，构建Activity的子类就是Andoid外特性空间展现的接口。我们可以从下面的简单的例子描述看看Activity，到底如何建立的。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">DemoActivity extend Activity</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">{</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp; onCreate</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; onResume</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; onPause</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; onStop</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">}</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 在Android的外特性空间(SDK)中，Android应用程序员根本不知道进程是什么时候起来的，系统消息是如何传递过来的。这个DemoActivity是如何实例化的呢？并且该Activity是托管在哪个进程的呢？本节的分析将给出答案。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">我们从ActivityThread中可以看到在应用进程中的Activity都被放置在mActivities中。</font></p>
<a href="file:///C:/Users/lenovo/AppData/Local/Temp/WindowsLiveWriter-429641856/supfilesB73AD1/image5.png" style="text-decoration: none; color: #336699; "><img title="image_thumb3" border="0" alt="image_thumb3" src="http://hi.csdn.net/attachment/201005/24/0_1274715099YZq5.gif" width="442" height="357" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 这些ActivityRecord记录了应用进程中，程序员建立的Activity子类的实例，我们称之为外特性空间的Activity。这些Activity类实例是放在应用程序端进行实际交互的Activity，而为了管理这些Activity，AMS内核中还有一个影子Activity，被称为HistoryRecord。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">3.2 Activity与HistoryRecord的关系</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp; 在整个系统中，Activity实际上有两个实体。一个在应用进程中跟应用程序员打交道的Activity，一个是在AMS的中具有管理功能的History Record。应用进程中的Activity都登记ActivityThread实例中的mActivity数组中，而在AM端，HistroytRecord实例放置在mHistroy栈中。mHistory栈是Android管理Activity的场所，放置在栈顶的就是User看到的处于活动状态的Activity。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">Activity与HistrotyRecord的关系图可以表示如下：</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><a href="file:///C:/Users/lenovo/AppData/Local/Temp/WindowsLiveWriter-429641856/supfilesB73AD1/image10.png" style="text-decoration: none; color: #336699; "><img title="image_thumb6" border="0" alt="image_thumb6" src="http://hi.csdn.net/attachment/201005/24/0_1274715100aYL1.gif" width="476" height="679" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Activity的内核实体是依靠在ProcessRecord的成员变量中，通过ProcessRecord我们可以访问到所有的属于该Process的Activity。而在ProcessRecord记录了与应用进程之间的联系：IActivtityThread接口。通过该接口，可以访问到所对应的Activity的方法。在Launch Activity时，AMS将对应的HistoryRecord作为token传递到客服端和客服端的Activity建立联系。在AMS中Activity状态变化时，将通过该联系找到客服端的Activity，从而将消息或者动作传递应用程序面对的接口：xxxActivity。</font></p>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font face="宋体">3.3 Actvity的Launch过程</font></h3>
<blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">1)发起请求startActivity(intent)</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">2）Activity Service Manager接收到请求执行StartActivity函数。</font></p>
</blockquote><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 建立：HistoryRecord实例r.</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 将r 加入到mHistory顶。</font></p>
</blockquote><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">（3）通过app.thread.scheduleLaunchActvity(&nbsp;</font><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#97;&#112;&#112;&#44;&#114;&#41;&#64;&#65;&#99;&#116;&#105;&#118;&#105;&#116;&#121;&#84;&#104;&#114;&#101;&#97;&#100;&#46;&#106;&#97;&#118;&#97;" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">app,r)@ActivityThread.java</font></a></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">（4）在App应用中建立新的ActivityRecord。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">（5）建立新的Activity对象并放入到ActivityRecord中。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">（6）将ActivityRecord加入到mActivites@ActivityThread</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">(7)发起Activity.onCreate(..),,该onCreate就是在你的应用程序XXXActivity中的onCreate。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&nbsp;&nbsp;<a href="file:///C:/Users/lenovo/AppData/Local/Temp/WindowsLiveWriter-429641856/supfilesB73AD1/image16.png" style="text-decoration: none; color: #336699; "><img title="image_thumb10" border="0" alt="image_thumb10" src="http://hi.csdn.net/attachment/201005/24/0_1274715102szL9.gif" width="690" height="870" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: inline; " /></a></p>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">3.4 Activity的Resume</h3>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">（1）Activity什么时候被Resume</font></p>
</blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><a href="file:///C:/Users/lenovo/AppData/Local/Temp/WindowsLiveWriter-429641856/supfilesB73AD1/image21.png" style="text-decoration: none; color: #336699; "><img title="image_thumb13" border="0" alt="image_thumb13" src="http://hi.csdn.net/attachment/201005/24/0_12747151046D00.gif" width="646" height="487" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">（2）Rusume的过程</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 通过该过程的研究我们会进一步的了解到AMS与应用进程的交互过程。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">在AMS端，满足resume条件都会调用：</font><font size="4" face="宋体">Resume的核心函数：<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#101;&#115;&#117;&#109;&#101;&#84;&#111;&#112;&#65;&#99;&#116;&#105;&#118;&#105;&#116;&#121;&#76;&#111;&#99;&#107;&#101;&#100;&#64;&#65;&#99;&#116;&#105;&#118;&#105;&#116;&#121;&#77;&#97;&#110;&#97;&#103;&#101;&#114;&#83;&#101;&#114;&#118;&#105;&#99;&#101;" style="text-decoration: none; color: #336699; ">resumeTopActivityLocked@ActivityManagerService</a></font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">XXX当前栈顶的HistroyRecord</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">1）窗口切换：隐藏前一个Activity的窗口，</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">2）更新LRUList，（LRUList是淘汰应用程序的依据之一）</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">3) XXX.app.thread.scheduleResumeActivity(XXX,</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isNextTransitionForward());</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">4)completeResumeLocked</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp; setFocusedActivityLocked</font></p>
<blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mFocusActivity=xxx&nbsp; //此时焦点Actvitiy切换了。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WM.setFocusedApp(xxx,</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mWindowManager.executeAppTransition();</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mNoAnimActivities.clear();</font></p>
</blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">在应用程序端：</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">（5）scheduleResumeActivity</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">handleResumeActivity(IBinder token, boolean clearHide, boolean isForward) {</font></p>
<blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">ActivityRecord r = performResumeActivity(token, clearHide);</font></p>
</blockquote><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp; ActivityRecord r = mActivities.get(token);</font></p>
</blockquote><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp; r.activity.performResume()</font></p>
</blockquote><blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; background-position: initial initial; background-repeat: initial initial; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; performResume</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">整个Resume的过程如下：</font></p>
</blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><a href="file:///C:/Users/lenovo/AppData/Local/Temp/WindowsLiveWriter-429641856/supfilesB73AD1/image26.png" style="text-decoration: none; color: #d59139; "><img title="image_thumb16" border="0" alt="image_thumb16" src="http://hi.csdn.net/attachment/201005/24/0_1274715105fdaw.gif" width="590" height="800" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></p>
</div>
<img src ="http://www.blogjava.net/yglwxl/aggbug/332835.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2010-09-25 15:39 <a href="http://www.blogjava.net/yglwxl/archive/2010/09/25/332835.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>（转）Android核心分析（21）----Android应用框架之AndroidApplication</title><link>http://www.blogjava.net/yglwxl/archive/2010/09/25/332834.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Sat, 25 Sep 2010 07:38:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2010/09/25/332834.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/332834.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2010/09/25/332834.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/332834.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/332834.html</trackback:ping><description><![CDATA[<h1 align="center" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 1.5em; font-size: 15px; font-family: 'Microsoft yahei', heiti, verdana, sans-serif; line-height: 30px; "><span  style="font-size: x-large;"><span style="color: red; "><span style="font-size: 24pt; "><span style="font-size: 36pt; "><span style="font-size: 8pt; "><span style="font-size: 10pt; "></span></span></span></span><span style="font-size: 10pt; "><span style="font-size: 24pt; "><span style="font-size: 36pt; "><span style="font-size: 8pt; "><span style="font-size: 10pt; "><span style="font-family: 黑体; ">From</span></span></span></span></span>&nbsp;&nbsp;</span></span></span><span  style="color: #000000; font-family: Simsun; font-weight: normal; line-height: normal; font-size: medium; "><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx">http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx</a></span></h1>
<h1 align="center" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0.5em; padding-left: 1.5em; font-size: 15px; font-family: 'Microsoft yahei', heiti, verdana, sans-serif; line-height: 30px; "><font size="5">Android Application</font></h1>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; Android提供给开发程序员的概念空间中Application只是一个松散的表征概念，没有多少实质上的表征。在Android实际空间中看不到实际意义上的应用程序的概念,即使有一个叫Application的类，这个也就是个应用程序上下文状态，是一个极度弱化的概念。Application只是一个空间范畴的概念，Application就是Activity，Service之类的组件上下文描述。Application并不是Android的核心概念，而Activity才是Android的核心概念。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 从Android的SDK文档中，我们知道一般情况Android应用程序是由以下四种组件构造而成的：Activity，Broadcast Intent Receiver，服务（Service），内容提供器（Content Provider）。我们可以使用下面的图来表示一下Android的概念空间。这些组件依附于应用程序中，应用程序并不会一开始就建立起来，而是在这些组件建立起来后，需要运行时，才开始建立应用程序对象。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><a href="http://hi.csdn.net/attachment/201005/24/0_1274715036pPGc.gif" style="text-decoration: none; color: #336699; "><img title="image" border="0" alt="image" src="http://hi.csdn.net/attachment/201005/24/0_127471503710zt.gif" width="616" height="473" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></p>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; ">2.1应用进程名称</h3>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 为什么要从应用进程名称开始？作为内核研究，我们还是回到问题的最本质处：不管Activity，Service等组件如何设计和运行，它要提供服务，就必须要依附在Linux的进程上，建立消息循环，组件才能够真正的运作。Activity实例是如何Hosting在Linux进程上的？这个是我们首先想要弄明白的。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">我们在</font><a href="http://androidappdocs.appspot.com/guide/topics/manifest/manifest-element.html" style="text-decoration: none; color: #336699; "><font size="4" face="宋体"><manifest></manifest></font></a><font size="4" face="宋体">的<application>项目中看到android:</application></font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#proc#proc" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">process</font></a><font size="4" face="宋体">="string"这个定义。</font></p>
<blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体"><application android:=""></application></font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#clear#clear" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">allowClearUserData</font></a><font size="4" face="宋体">=["true" | "false"]&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#reparent#reparent" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">allowTaskReparenting</font></a><font size="4" face="宋体">=["true" | "false"]&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#agent#agent" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">backupAgent</font></a><font size="4" face="宋体">="string"&nbsp;<br />
&#8230;</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#label#label" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">label</font></a><font size="4" face="宋体">="string resource"&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#space#space" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">manageSpaceActivity</font></a><font size="4" face="宋体">="string"&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#nm#nm" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">name</font></a><font size="4" face="宋体">="string"&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#prmsn#prmsn" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">permission</font></a><font size="4" face="宋体">="string"&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#persistent#persistent" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">persistent</font></a><font size="4" face="宋体">=["true" | "false"]&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#proc#proc" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">process</font></a><font size="4" face="宋体">="string"&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#restoreany#restoreany" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">restoreAnyVersion</font></a><font size="4" face="宋体">=["true" | "false"]&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#aff#aff" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">taskAffinity</font></a><font size="4" face="宋体">="string"&nbsp;<br />
android:</font><a href="http://blog.csdn.net/maxleng/archive/2010/05/24/5621345.aspx#theme#theme" style="text-decoration: none; color: #336699; "><font size="4" face="宋体">theme</font></a><font size="4" face="宋体">="resource or theme" &gt;&nbsp;<br />
&nbsp;&nbsp;&nbsp; . . .&nbsp;<br />
</font></p>
</blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">在SDK用已经描述的很清楚到了。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">android:process</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">The name of a process where all components of the application should run. Each component can override this default by setting its own process attribute.</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">By default, Android creates a process for an application when the first of its components needs to run. All components then run in that process. The name of the default process matches the package name set by the&nbsp;</font><a href="http://androidappdocs.appspot.com/guide/topics/manifest/manifest-element.html" style="text-decoration: none; color: #336699; "><font size="4" face="宋体"><manifest></manifest></font></a><font size="4" face="宋体">element.</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">By setting this attribute to a process name that's shared with another application, you can arrange for components of both applications to run in the same process — but only if the two applications also share a user ID and be signed with the same certificate.</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">为什么要提出这么一个定义？android:process名称。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 默认状态下，Activity Manager Service在应用程序的第一个组件需要运行时将会为应用程序建立一个进程，而这个进程的名字就是android:process=&#8221;string&#8221;所指定，缺省的是应用程序包的名字。该进程一旦建立，后面的该应用的组件都将运行在该进程中，他们绑定的根据就是这个Android：Process指定的名称，因为在他们都在同一个应用程序包里，也就具有了同样的进程名字，于是他们都托管在了同一进程中。组件将通过ClassLoader从Package中获取到应用程序的信息。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 在建立Actvitiy时，如果在应用进程端没有应用对象，系统在该过程中利用makeApplication建立一个Application对象，实例化"android.app.Application"，建立一个应用程序上下文完成例如资源，package等信息管理。</font></p>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; ">2.2&nbsp; ActivityThread运行框架</h3>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 在分析中，我们可以看到真正对应应用进程的不是Application而是ActivityThread。我们从实际的应用堆栈可以看到：</font></p>
<blockquote style="border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; border-top-color: #98a47f; border-right-color: #98a47f; border-bottom-color: #98a47f; border-left-color: #98a47f; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f5f5f5; font: normal normal normal 12px/normal simsun; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; margin-top: 10px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; ">
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><font size="4" face="宋体">NaiveStart.main()</font></p>
</blockquote>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ZygoteInit.main</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ZygoteInit$MethodAndArgsCall.run</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method.Invoke</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size="4" face="宋体">method.invokeNative</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActivityThread.main()</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Looper.loop()</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size="4" face="宋体">....</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 每个应用程序都以ActivityThread.main()为入口进入到消息循环处理。对于一个进程来讲，我们需要这个闭合的处理框架。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><a href="http://hi.csdn.net/attachment/201005/24/0_1274715037oaa7.gif" style="text-decoration: none; color: #336699; "><img title="image" border="0" alt="image" src="http://hi.csdn.net/attachment/201005/24/0_1274715038fxsy.gif" width="260" height="190" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; ActivitiyThread是应用程序概念空间的重要概念，他建立了应用进程运行的框架，并提供了一个IActivityThread接口作为与Activity Manager Service的通讯接口.通过该接口AMS可以将Activity的状态变化传递到客户端的Activity对象。</font></p>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; ">2．3 ActivitiyThread的建立</h3>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">为了叙述的方便我将Actvitiy Manager Service简写成AMS。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 在AMS中关于应用程序的概念是ProcessRecord，请求都是从Activity，Service&#8230;等开始的，在Activity需要Resume时，此时如果与Activity相关的应用进程没有起来，AM则启动应用进程。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">AMS与应用进程的绑定分为两个部分，第一部分就是AM建立应用进程，第二部分就是应用进程Attach到AM，与AM建立通讯通道。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">1）创建建立进程：startProcessLocked(processName,Appinfo.uid)。该函数在StartSecificActivityLocked等调用。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">（1）建立ProcessRecord对象app,并将该对象添加到mProcessNames中。应用对象在mProcessNames中使用应用名字和uid来标识自己。如果在同一个Package中的Activity,如果都使用默认设置，那么这些Activity都会托管在同一个进程中，这是因为他们在带的ApplicationInfo中的ProcessName都是一样的。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><a href="http://hi.csdn.net/attachment/201005/24/0_1274715038X0aT.gif" style="text-decoration: none; color: #336699; "><img title="image" border="0" alt="image" src="http://hi.csdn.net/attachment/201005/24/0_1274715039jMzm.gif" width="430" height="196" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a>&nbsp;</p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><a href="http://hi.csdn.net/attachment/201005/24/0_12747150398uU3.gif" style="text-decoration: none; color: #336699; "><img title="image" border="0" alt="image" src="http://hi.csdn.net/attachment/201005/24/0_1274715040PA0P.gif" width="380" height="199" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">mPidsSelfLocked数组记录了PID，这个将会在应用进程跑起来后，将自己Attach到AM时，根据pid找到自己的前世：ProcessRecord.</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">2）android.app.ActivityThread进程启动</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp;&nbsp; Android.app.ActivityThread进程建立后，将跳入到ActivityThread的main函数开始运行，进入消息循环。</font><a href="http://hi.csdn.net/attachment/201005/24/0_1274715040RR9z.gif" style="text-decoration: none; color: #336699; "><img title="image" border="0" alt="image" src="http://hi.csdn.net/attachment/201005/24/0_1274715041z6df.gif" width="357" height="228" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 应用进程使用thread.attach()发起AMS的AttachApplicationLocked调用，并传递 ActvitiyThread对象和CallingPid。AttachApplicationLocked将根据CallingPid在mPidsSelfLocked找到对应的ProcessRecord实例app,将ActvitiyThread放置app.thread中。这样应用进程和AMS建立起来双向连接。AM可以使用AIDL接口，通过app.thread可以访问应用进程的对象。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">&nbsp;&nbsp;&nbsp; 应用程序通过ActivityThread提供的框架，建立消息循环Looper和Handler。从前面的相关章节我们知道有Looper和Handler,整个系统就可以运作了。</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; "><font size="4" face="宋体">为了更为系统的了解应用程序的建立时序及其涉及到数据操作，我给出了应用进程的建立过程示意图：</font></p>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; line-height: 30px; font-size: 13.8889px; ">&nbsp;<a href="http://hi.csdn.net/attachment/201005/24/0_12747150430h53.gif" style="text-decoration: none; color: #d59139; "><img title="image" border="0" alt="image" src="http://hi.csdn.net/attachment/201005/24/0_1274715044V5Fa.gif" width="692" height="727" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; display: block; float: none; margin-left: auto; margin-right: auto; " /></a></p>
<img src ="http://www.blogjava.net/yglwxl/aggbug/332834.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2010-09-25 15:38 <a href="http://www.blogjava.net/yglwxl/archive/2010/09/25/332834.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Activitie之间传对象,通过Parcelable(转)</title><link>http://www.blogjava.net/yglwxl/archive/2010/09/10/331678.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Fri, 10 Sep 2010 08:00:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2010/09/10/331678.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/331678.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2010/09/10/331678.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/331678.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/331678.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 对象必须实现Serializable，对象代码如下：Java代码&nbsp;    import&nbsp;java.io.Serializable;&nbsp;&nbsp;    &nbsp;&nbsp;    import&nbsp;android.graphics.drawable.Drawable;&nbsp;&nbsp;    &nbsp;&nbsp;...&nbsp;&nbsp;<a href='http://www.blogjava.net/yglwxl/archive/2010/09/10/331678.html'>阅读全文</a><img src ="http://www.blogjava.net/yglwxl/aggbug/331678.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2010-09-10 16:00 <a href="http://www.blogjava.net/yglwxl/archive/2010/09/10/331678.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>版本与固件刷包知识讲解(转)</title><link>http://www.blogjava.net/yglwxl/archive/2009/03/20/261030.html</link><dc:creator>九宝</dc:creator><author>九宝</author><pubDate>Fri, 20 Mar 2009 06:07:00 GMT</pubDate><guid>http://www.blogjava.net/yglwxl/archive/2009/03/20/261030.html</guid><wfw:comment>http://www.blogjava.net/yglwxl/comments/261030.html</wfw:comment><comments>http://www.blogjava.net/yglwxl/archive/2009/03/20/261030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yglwxl/comments/commentRss/261030.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yglwxl/services/trackbacks/261030.html</trackback:ping><description><![CDATA[<h2>版本与固件刷包知识讲解</h2>
<div class="t_msgfont" id="postmessage_3690886">
<p align="left"><font face="宋体 "><font color="#000000">　　看到可能很多朋友对于G1版本的不解，我就把我的理解发出来分享给大家<br />
如果有疑问或者建议可以提出来，我们互相学习进步，有不对的指出请指出，新手也可以看看，帮助学习理解G1的版本问题。<br />
　　杰尼原创，转载请注明<br />
</font></font><font color="#000000"></font><br />
<font face="宋体 "><font color="#000000">　　通常我们所说的关键词有很多比如RC30 RC8&nbsp;&nbsp;RC33&nbsp;&nbsp;JFV1.31&nbsp;&nbsp;JFV.1.41&nbsp;&nbsp;汉化包&nbsp;&nbsp;主题包&nbsp;&nbsp;降级包之类的<br />
下面我来详细解释下。</font></font></p>
<font face="宋体 "><font color="#000000"><br />
<p align="center"></font></font><font face="宋体 "></font></p>
<font face="宋体 "><br />
<font color="#000000"><font size="2"><font color="#ff0000">首先我来解释下关于你进入设置后看到About phone的信息<br />
</font></font><br />
　　如上图<br />
　　Status 是你手机硬件的一些规格信息，状态信息<br />
　　Legal information 是指的硬件厂商，服务厂商的信息<br />
　　Contributors 贡献者的一个信息列表<br />
<br />
　　总之前三个没什么用<br />
<br />
　　看下面&nbsp;&nbsp;Model number 指的你设备信息&nbsp;&nbsp;我们用G1 <br />
　　所以看到的是 T—mobile G1<br />
<br />
　　下面的 Firmware version<br />
　　这个是固件版本<br />
　　目前的所有G1基本上都是1.0的<br />
　　传说中的Cupcake好像是1.5的<br />
<br />
　　Baseband version<br />
　　是基础板版本&nbsp;&nbsp;这个对于我们来讲没太大认知作用，略讲<br />
<br />
　　Kernel version<br />
　　内核版本<br />
　　我们可以看到Jesusfreke<br />
　　没错就是传说中的 JF<br />
　　只是个作者信息罢了，说明了这个版本是JF的自制版<br />
<br />
　　下面Build number<br />
　　是固件版本<br />
　　我们可以看到常见提到的&nbsp;&nbsp;TC4-RC30</font><br />
<font color="#000000">　　现在最新的是更新到了　TC4-RC33</font><br />
<font color="#000000"><br />
</font><font color="#000000"><font size="2"><font color="#ff0000">下面讲解一下经常提到的版本RC30 RC8&nbsp;&nbsp;RC33之类的信息<br />
<br />
</font>　　由于G1是运营商合作的产物，所以现在分为美版和英版</font><br />
<font size="2">　　美版机器从发布到现在分为RC19,RC28,RC29，RC30，RC31,RC33几个版本</font><br />
<font size="2">　　目前RC31,RC33只是少部分给美国用户升级了，基本上就是做测试用的</font><br />
<font size="2"></font><br />
<font size="2">　　英版从发布到现在RC5,RC7,RC8几个版本</font><br />
<font size="2"></font><br />
<font size="2">　　美国版本命名基本上是TC4-RCXX，而应该版应该是TC5-RCX</font><br />
<font size="2">　　从RC29到RC30这样的升级，我们可以理解为升级小补丁包，官方进行小幅度更新，弥补漏洞用的</font><br />
<font size="2"></font><br />
<br />
<font size="2"><font color="#ff0000">关于Cupcake是什么？Cupcake和新闻的RC33哪个高的问题</font></font><br />
<font size="2"></font><br />
<font size="2">　　Cupcake是一个代号，就跟Windows vista之前代号是Longhorn是的</font><br />
<font size="2">　　Cupcake应该算是一个大的升级了，很久前就开始炒了，预定应该月底能出来，现在还在测，</font><br />
<font size="2">　　新的功能主要包括了可以摄像，中文界面，多触点等功能，比较大的升级</font><br />
<font size="2">　　同时目前来说Cupcake的固件信息应该是1.5</font><br />
<font size="2"></font><br />
<font size="2">　　RC33基本上还是个小补丁，算过渡Cupcake的小包吧，我们可以看到固件升级到1.1，所以</font><br />
<font size="2">　　RC33是小补丁包，Cupcake是一个大升级。</font><br />
<font size="2"></font><br />
<font size="2"><font color="#ff0000">关于JFV1.31&nbsp;&nbsp;JFV.1.41&nbsp;&nbsp;的相关内容</font></font><br />
<font size="2"></font><br />
<font size="2">　　JFV全称应该是</font><br />
　　Jesus freke verson<br />
　　也就是这个作者做的自制固件，简单的说他突破了官方版无法拥有ROOT权限的功能，并且解开了一些官方屏蔽的功能<br />
　　比如JFV1.41支持的多触点浏览网页等。<br />
<br />
<font size="2"><font color="#ff0000">关于主题包</font></font><br />
<br />
　　目前G1所谓的拥有主题功能，其实是需要刷一个主题包，由于拥有了Auto-sign签名程序，我们可以自己更换喜欢的图片从而实现主题功能<br />
　　这个刷包的话，需要根据主题制作对应的版本，也就是说有点主题是JFV1.31 有的是JFV 1.41的<br />
　　需要看清，当然刷你就需要用自制固件<br />
　　另外关于担心刷坏主题这个问题<br />
　　其实目前来讲，刷包对于G1是很常见的，如果有兴趣玩的话还是建议多看看这方面内容，刷包很简单，但是你最好刷前备份自己的信息资料<br />
<br />
<font size="2"><font color="#ff0000">关于降级包<br />
</font></font><br />
<font size="2">　　DREAIMG.nbh，这个是用来帮你降级到RC29的包，我们进入Bootloader模式，可以用来降级，其实如果你刷手机由于操作不当等诸多情况</font><br />
<font size="2">　　都可以用其来降级的，所以不必担心</font><br />
</font></font></div>
 <img src ="http://www.blogjava.net/yglwxl/aggbug/261030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yglwxl/" target="_blank">九宝</a> 2009-03-20 14:07 <a href="http://www.blogjava.net/yglwxl/archive/2009/03/20/261030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>