??xml version="1.0" encoding="utf-8" standalone="yes"?>成视频在线免费观看,蜜桃免费一区二区三区,深夜影院在线观看http://www.aygfsteel.com/lincode/category/49630.htmlzh-cnTue, 20 Sep 2011 13:18:35 GMTTue, 20 Sep 2011 13:18:35 GMT60[android] PhoneGap ?android 下的实现原理http://www.aygfsteel.com/lincode/archive/2011/09/20/359014.htmllincodelincodeTue, 20 Sep 2011 02:20:00 GMThttp://www.aygfsteel.com/lincode/archive/2011/09/20/359014.htmlhttp://www.aygfsteel.com/lincode/comments/359014.htmlhttp://www.aygfsteel.com/lincode/archive/2011/09/20/359014.html#Feedback0http://www.aygfsteel.com/lincode/comments/commentRss/359014.htmlhttp://www.aygfsteel.com/lincode/services/trackbacks/359014.htmlPhoneGap 是一个移动开发框架。通过 PhoneGapQ开发者可以?JavaScript 调用手机的原生功能,例如Q获取经U度Q让手机振动{?br />主页 http://www.phonegap.com/ ?br />源码 https://github.com/phonegap/phonegap-android ?br />
PhoneGap 在早期,应该是?WebView ?addJavaScriptInterface Ҏ(gu)Q来?JS 提供调用原生功能可能。addJavaScriptInterface Q可以将一?Java 对象l定C?JS 对象。是的,JS对象可以调用 JavaҎ(gu)。但?PhoneGap 1.0.0 q个版本中,PhoneGap 改变了方法?br />
以振动功能ؓ例,我们可以看一下程序调用的程Q?br />
1 ?JS 中,启动命o

main.js / navigator.notification.vibrate(0);

notification.js / Notification.vibrate.vibrate 中执行了 PhoneGap.exec(null, null, "Notification", "vibrate", [mills]);

phonegap.js / PhoneGap.exc 中执行了 var r = prompt(PhoneGap.stringify(args), "gap:"+PhoneGap.stringify([service, action, callbackId, true]));

q时QWebView ׃企图弹出一个窗口。这时?android 提供?nbsp;WebChromeClient ?nbsp;API 可以截?WebView 的这个动??br />
2 JAVA 中,处理命o
WebView ?WebChromClient 实现了下面这个函敎ͼ

public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result)

?onJsPrompt 中执行了 String r = pluginManager.exec(service, action, callbackId, message, async);

PlugManager 会根据收到参敎ͼ命令分发给特定?Plugin。这个例子中Q接收的 plugin 是:Notification?br />落实?Notification ?exec 函数Q会执行q一行: this.vibrate(args.getLong(0));

振动的实CؓQ?br />

 

 public void vibrate(long time){
        
// Start the vibration, 0 defaults to half a second.
        if (time == 0) {
time 
= 500;
}
        Vibrator vibrator 
= (Vibrator) this.ctx.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(time);
}

 


3 Java 处理完后的数据,需要给 JS 一个反馈:
q里 PhoneGap 使用了一个在客户端本地实现的 XHRServerQ具体到代码中就是一个JAVA c?CallbackServer?br />
分两个部分介l其行ؓQ?br />本地 XHRServerQ?br />思想是,后台每执行完一个命令,都会结果存?CallbackServer 中的一个链表中Q具体ؓCallbackServr?private LinkedList<String> javascript;
q个l果其实是一D字W串表示?JS 函数调用。例如检网l调用的l果为:PhoneGap.callbackSuccess('Network Status1',{status:1,message:"wifi",keepCallback:true});
 XHRServer 的行为很单,只要有请求来Q就把链表中的最先进来的提出来,q回l客L。没有请求来Q则 10U钟q回一个空的回复,以维持XHRServer?div>Webview 作ؓ客户端:
?WebView 中,会有一个轮询机Ӟq可以参?PhoneGap.JSCallack ?nbsp;PhoneGap.JSCallbackPolling 两个函数来访?XHRServer。XHRServerQ返回的l果是 WebView 需要调用的 JS 函数??JS 中,eval() 函数Q将q回的结果变Z个可以执行的对象Q在 Webview 中执行,可以认ؓq即是回调函?Callback。这也是Z?PhoneGap Z命名 XHRServer ?CallbackServer 的原因?br />


lincode 2011-09-20 10:20 发表评论
]]>
[android] Serializable ?Parcelable 区别http://www.aygfsteel.com/lincode/archive/2011/09/16/358805.htmllincodelincodeFri, 16 Sep 2011 08:16:00 GMThttp://www.aygfsteel.com/lincode/archive/2011/09/16/358805.htmlhttp://www.aygfsteel.com/lincode/comments/358805.htmlhttp://www.aygfsteel.com/lincode/archive/2011/09/16/358805.html#Feedback0http://www.aygfsteel.com/lincode/comments/commentRss/358805.htmlhttp://www.aygfsteel.com/lincode/services/trackbacks/358805.htmlandroid ?span class="Apple-style-span" style="background-color: #ffffff; ">自定义的对象序列化的问题有两个选择一个是ParcelableQ另外一个是Serializable?/span>

一 序列化原因:

1.怹性保存对象,保存对象的字节序列到本地文g中;
2.通过序列化对象在|络中传递对象;
3.通过序列化在q程间传递对象?nbsp;

?至于选取哪种可参考下面的原则Q?/span>

1.在用内存的时候,Parcelable cLSerializable性能高,所以推荐用ParcelablecR?br style="line-height: 25px; " />2.Serializable在序列化的时候会产生大量的时变量,从而引起频J的GC?br style="line-height: 25px; " />3.Parcelable不能使用在要数据存储在盘上的情况Q因为Parcelable不能很好的保证数据的持箋性在外界有变化的情况下。尽Serializable效率低点Q?也不提倡用Q但在这U情况下Q还是徏议你用Serializable ?/span>


实现Q?/strong>
1 Serializable 的实玎ͼ只需要? implements Serializable 卛_。这只是l对象打了一个标讎ͼpȝ会自动将其序列化?br />
2 Parcelabel 的实玎ͼ需要在cMd一个静态成员变?CREATORQ这个变量需要?Parcelable.Creator 接口?br />
public class MyParcelable implements Parcelable {
     
private int mData;

     
public int describeContents() {
         
return 0;
     }

     
public void writeToParcel(Parcel out, int flags) {
         out.writeInt(mData);
     }

     
public static final Parcelable.Creator<MyParcelable> CREATOR
             
= new Parcelable.Creator<MyParcelable>() {
         
public MyParcelable createFromParcel(Parcel in) {
             
return new MyParcelable(in);
         }

         
public MyParcelable[] newArray(int size) {
             
return new MyParcelable[size];
         }
     };
     
     
private MyParcelable(Parcel in) {
         mData 
= in.readInt();
     }
 }

 

lincode 2011-09-16 16:16 发表评论
]]>
[android] Activity 的生命周?以及 横屏竖屏切换?Activity 的状态变?/title><link>http://www.aygfsteel.com/lincode/archive/2011/09/16/358768.html</link><dc:creator>lincode</dc:creator><author>lincode</author><pubDate>Fri, 16 Sep 2011 02:32:00 GMT</pubDate><guid>http://www.aygfsteel.com/lincode/archive/2011/09/16/358768.html</guid><wfw:comment>http://www.aygfsteel.com/lincode/comments/358768.html</wfw:comment><comments>http://www.aygfsteel.com/lincode/archive/2011/09/16/358768.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lincode/comments/commentRss/358768.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lincode/services/trackbacks/358768.html</trackback:ping><description><![CDATA[<strong>生命周期</strong><br /><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">Android pȝ在Activity 生命周期中加入一些钩子,我们可以在这些系l预留的钩子中做一些事情?br />例D?7 个常用的钩子Q?br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onCreate(Bundle savedInstanceState)<br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onStart()<br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onResume()<br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onPause()<br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onStop()<br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onRestart()<br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">protected void onDestroy()<br /><br />要说明:<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onCreate(Bundle savedInstanceState)Q创建activity时调用。设|在该方法中Q还以Bundle中可以提出用于创 Activity 所需的信息?br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onStart()Qactivity变ؓ在屏q上对用户可见时Q即获得焦点Ӟ会调用?br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onResume()Qactivity开始与用户交互时调用(无论是启动还是重新启动一个活动,该方法L被调用的Q?br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onPause()Qactivity被暂停或收回cpu和其他资源时调用Q该Ҏ(gu)用于保存zd状态的。?br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onStop()Qactivity被停止ƈ转ؓ不可见阶D及后箋的生命周期事件时Q即失去焦点时调用?br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onRestart()Q重新启动activity时调用。该zd仍在栈中Q而不是启动新的活动?br style="line-height: 22px; " /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; line-height: 22px; background-color: #ffffff; ">onDestroy()Qactivity被完全从pȝ内存中移除时调用Q该Ҏ(gu)被调用可能是因ؓ有h直接调用 finish()Ҏ(gu) 或者系l决定停止该zd以释放资源?br /></span><br /><strong>横竖屏切?/strong><br /><br />1 切换到横?br /><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onSaveInstanceState<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onPause<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStop<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onDestroy<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onCreate<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStart<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onRestoreInstanceState<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onResume<br /><br /></span>2 切换到竖屏,销毁了两次<br /><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onSaveInstanceState<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onPause<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStop<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onDestroy</span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onCreate<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStart<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onRestoreInstanceState<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onResume<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onSaveInstanceState<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onPause<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStop<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onDestroy<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onCreate<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onStart<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onRestoreInstanceState<br /></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #ffffff; ">onResume</span><br /><br /><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #f5fafe; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">3 修改AndroidManifest.xmlQ把该Activityd android:configChanges="orientation"Q切横屏Q只销毁一ơ?/p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">onSaveInstanceState<br />onPause<br />onStop<br />onDestroy<br />onCreate<br />onStart<br />onRestoreInstanceState<br />onResume</p></span>4 <span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #f5fafe; ">再切回竖屏,发现不会再打印相同信息,但多打印了一行onConfigChanged<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">onSaveInstanceState<br />onPause<br />onStop<br />onDestroy<br />onCreate<br />onStart<br />onRestoreInstanceState<br />onResume<br />onConfigurationChanged</p></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #f5fafe; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">5 更改 android:configChanges="orientation" Ҏ(gu) android:configChanges="orientation|keyboardHidden"Q切横屏Q就只打印onConfigChanged</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">onConfigurationChanged</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">6 切回竖屏</p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">onConfigurationChanged<br />onConfigurationChanged</p></span><span id="wmqeeuq" class="Apple-style-span" style="font-family: Arial, 宋体; line-height: 26px; background-color: #f5fafe; "><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">ȝQ?/p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">1、不讄Activity的android:configChangesӞ切屏会重新调用各个生命周期,切横屏时会执行一ơ,切竖屏时会执行两?/p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">2、设|Activity的android:configChanges="orientation"Ӟ切屏q是会重新调用各个生命周期,切横、竖屏时只会执行一?/p><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">3、设|Activity的android:configChanges="orientation|keyboardHidden"Ӟ切屏不会重新调用各个生命周期Q只会执行onConfigurationChangedҎ(gu)</p></span><br /><br /><br /><br /><img src ="http://www.aygfsteel.com/lincode/aggbug/358768.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lincode/" target="_blank">lincode</a> 2011-09-16 10:32 <a href="http://www.aygfsteel.com/lincode/archive/2011/09/16/358768.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ȫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">⴨</a>| <a href="http://" target="_blank">ͳ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͷ</a>| <a href="http://" target="_blank">ɣ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͨ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">߰</a>| <a href="http://" target="_blank">Ӽ</a>| <a href="http://" target="_blank">³</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʹ</a>| <a href="http://" target="_blank">ԭ</a>| <a href="http://" target="_blank">ӱʡ</a>| <a href="http://" target="_blank">Դ</a>| <a href="http://" target="_blank">ƴ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̩</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ϰˮ</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>