﻿<?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>C++博客-飛天-随笔分类-Android</title><link>http://www.cppblog.com/cjz/category/18054.html</link><description>快乐的生活......</description><language>zh-cn</language><lastBuildDate>Thu, 17 Nov 2011 08:55:32 GMT</lastBuildDate><pubDate>Thu, 17 Nov 2011 08:55:32 GMT</pubDate><ttl>60</ttl><item><title>SharedPreferences 简单用法</title><link>http://www.cppblog.com/cjz/archive/2011/11/17/160339.html</link><dc:creator>飛天</dc:creator><author>飛天</author><pubDate>Thu, 17 Nov 2011 06:01:00 GMT</pubDate><guid>http://www.cppblog.com/cjz/archive/2011/11/17/160339.html</guid><wfw:comment>http://www.cppblog.com/cjz/comments/160339.html</wfw:comment><comments>http://www.cppblog.com/cjz/archive/2011/11/17/160339.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/cjz/comments/commentRss/160339.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cjz/services/trackbacks/160339.html</trackback:ping><description><![CDATA[<div>SharedPreferences 相当于Ini文件功能。是以xml文件形式保存。<br />
<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->&nbsp;SharedPreferences&nbsp;android.content.ContextWrapper.getSharedPreferences(String&nbsp;name,&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;mode)<br />
<br />
<br />
<br />
<span style="color: #0000FF; ">public</span>&nbsp;SharedPreferences&nbsp;getSharedPreferences&nbsp;(String&nbsp;name,&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;mode)&nbsp;<br />
Since:&nbsp;API&nbsp;Level&nbsp;1&nbsp;<br />
Retrieve&nbsp;and&nbsp;hold&nbsp;the&nbsp;contents&nbsp;of&nbsp;the&nbsp;preferences&nbsp;file&nbsp;'name',&nbsp;returning&nbsp;a&nbsp;SharedPreferences&nbsp;through&nbsp;which&nbsp;you&nbsp;can&nbsp;retrieve&nbsp;and&nbsp;modify&nbsp;its&nbsp;values.&nbsp;Only&nbsp;one&nbsp;instance&nbsp;of&nbsp;the&nbsp;SharedPreferences&nbsp;object&nbsp;is&nbsp;returned&nbsp;to&nbsp;any&nbsp;callers&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;the&nbsp;same&nbsp;name,&nbsp;meaning&nbsp;they&nbsp;will&nbsp;see&nbsp;each&nbsp;other's&nbsp;edits&nbsp;as&nbsp;soon&nbsp;as&nbsp;they&nbsp;are&nbsp;made.<br />
<br />
Parameters<br />
name&nbsp;&nbsp;Desired&nbsp;preferences&nbsp;file.&nbsp;If&nbsp;a&nbsp;preferences&nbsp;file&nbsp;by&nbsp;<span style="color: #0000FF; ">this</span>&nbsp;name&nbsp;does&nbsp;not&nbsp;exist,&nbsp;it&nbsp;will&nbsp;be&nbsp;created&nbsp;when&nbsp;you&nbsp;retrieve&nbsp;an&nbsp;editor&nbsp;(SharedPreferences.edit())&nbsp;and&nbsp;then&nbsp;commit&nbsp;changes&nbsp;(Editor.commit()).&nbsp;<br />
mode&nbsp;&nbsp;Operating&nbsp;mode.&nbsp;Use&nbsp;0&nbsp;or&nbsp;MODE_PRIVATE&nbsp;<span style="color: #0000FF; ">for</span>&nbsp;the&nbsp;<span style="color: #0000FF; ">default</span>&nbsp;operation,&nbsp;MODE_WORLD_READABLE&nbsp;and&nbsp;MODE_WORLD_WRITEABLE&nbsp;to&nbsp;control&nbsp;permissions.&nbsp;The&nbsp;bit&nbsp;MODE_MULTI_PROCESS&nbsp;can&nbsp;also&nbsp;be&nbsp;used&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;multiple&nbsp;processes&nbsp;are&nbsp;mutating&nbsp;the&nbsp;same&nbsp;SharedPreferences&nbsp;file.&nbsp;MODE_MULTI_PROCESS&nbsp;is&nbsp;always&nbsp;on&nbsp;in&nbsp;apps&nbsp;targetting&nbsp;Gingerbread&nbsp;(Android&nbsp;2.3)&nbsp;and&nbsp;below,&nbsp;and&nbsp;off&nbsp;by&nbsp;<span style="color: #0000FF; ">default</span>&nbsp;in&nbsp;later&nbsp;versions.&nbsp;<br />
<br />
Returns<br />
Returns&nbsp;the&nbsp;single&nbsp;SharedPreferences&nbsp;instance&nbsp;that&nbsp;can&nbsp;be&nbsp;used&nbsp;to&nbsp;retrieve&nbsp;and&nbsp;modify&nbsp;the&nbsp;preference&nbsp;values.</div>
<br />
一、读取内容<br />
<br />
&nbsp; &nbsp;<span class="Apple-style-span" style="font-size: 13px; background-color: #eeeeee; ">SharedPreferences&nbsp;preferences&nbsp;</span><span class="Apple-style-span" style="font-size: 13px; background-color: #eeeeee; ">=</span><span class="Apple-style-span" style="font-size: 13px; background-color: #eeeeee; ">&nbsp;getSharedPreferences(</span><span class="Apple-style-span" style="font-size: 13px; background-color: #eeeeee; ">"</span><span class="Apple-style-span" style="font-size: 13px; background-color: #eeeeee; ">PCINFO</span><span class="Apple-style-span" style="font-size: 13px; background-color: #eeeeee; ">"</span><span class="Apple-style-span" style="font-size: 13px; background-color: #eeeeee; ">,&nbsp;MODE_APPEND);</span></div>
<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all">String&nbsp;strAddr&nbsp;=&nbsp;preferences.getString("PCADDR",&nbsp;"10.0.2.2");<br />
String&nbsp;strPort&nbsp;=&nbsp;&nbsp;preferences.getString("PCPORT","6699");<br />
</div><br />二、写入数据<br /><br /><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->SharedPreferences&nbsp;preference&nbsp;=&nbsp;getSharedPreferences("PCINFO",&nbsp;MODE_APPEND&nbsp;)&nbsp;;<br />Editor&nbsp;editor&nbsp;=&nbsp;preference.edit();<br />editor.putString("PCADDR",&nbsp;strAddr);<br />editor.putString("PCPORT",&nbsp;strPort);<br />editor.commit();</div><img src ="http://www.cppblog.com/cjz/aggbug/160339.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cjz/" target="_blank">飛天</a> 2011-11-17 14:01 <a href="http://www.cppblog.com/cjz/archive/2011/11/17/160339.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android模拟器与本地机器的相互访问</title><link>http://www.cppblog.com/cjz/archive/2011/11/04/159624.html</link><dc:creator>飛天</dc:creator><author>飛天</author><pubDate>Fri, 04 Nov 2011 07:45:00 GMT</pubDate><guid>http://www.cppblog.com/cjz/archive/2011/11/04/159624.html</guid><wfw:comment>http://www.cppblog.com/cjz/comments/159624.html</wfw:comment><comments>http://www.cppblog.com/cjz/archive/2011/11/04/159624.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cjz/comments/commentRss/159624.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cjz/services/trackbacks/159624.html</trackback:ping><description><![CDATA[<h4>1.Android模拟器连到PC<br />
</h4>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<h4>
<p><span class="Apple-style-span" style="font-weight: normal; ">android 本地地址 127.0.0.1,PC地址为10.0.2.2</span></p>
</h4>
</blockquote>
<h3>2.PC连到Android模拟器</h3>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<p><span class="Apple-style-span" style="font-weight: normal; ">&nbsp; &nbsp;需要进行端口映射：</span></p>
<span class="Apple-style-span" style="font-weight: normal;">如</span>：<span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-weight: normal; line-height: 26px; text-align: left; background-color: #ffffff; font-family: 宋体; "><code 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; ">adb forward tcp</span></code><code 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; color: #0000cc; ">:</span></code><code 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; ">6100 tcp</span></code><code 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; color: #0000cc; ">:</span></code><code 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; ">7100</span></code></span><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-family: Arial; font-weight: normal; line-height: 26px; text-align: left; background-color: #ffffff; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; ">&nbsp;</span></span><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-weight: normal; line-height: 26px; text-align: left; background-color: #ffffff; font-family: 宋体; "><code 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; color: #ff9900; ">// PC</span></code><code 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; color: #ff9900; ">上所有<span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; ">6100</span>端口通信数据将被重定向到手机端<span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; ">7100</span>端口<span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; ">server</span>上<br />
</span></code></span>
<p><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-weight: normal; line-height: 26px; text-align: left; background-color: #ffffff; font-family: 宋体; "><code 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "><span 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; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 13.5pt; ">所以访问PC本地的6100端口就相当于访问android上的7100端口</span></code></span></p>
</blockquote>
<p>&nbsp;</p>
<img src ="http://www.cppblog.com/cjz/aggbug/159624.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cjz/" target="_blank">飛天</a> 2011-11-04 15:45 <a href="http://www.cppblog.com/cjz/archive/2011/11/04/159624.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hello Android</title><link>http://www.cppblog.com/cjz/archive/2011/11/04/159608.html</link><dc:creator>飛天</dc:creator><author>飛天</author><pubDate>Fri, 04 Nov 2011 06:00:00 GMT</pubDate><guid>http://www.cppblog.com/cjz/archive/2011/11/04/159608.html</guid><wfw:comment>http://www.cppblog.com/cjz/comments/159608.html</wfw:comment><comments>http://www.cppblog.com/cjz/archive/2011/11/04/159608.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cjz/comments/commentRss/159608.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cjz/services/trackbacks/159608.html</trackback:ping><description><![CDATA[<div>Hello Android</div><img src ="http://www.cppblog.com/cjz/aggbug/159608.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cjz/" target="_blank">飛天</a> 2011-11-04 14:00 <a href="http://www.cppblog.com/cjz/archive/2011/11/04/159608.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>