Friday, February 6, 2009

android 幾個常用class

  • Intent
    可透過startActivity()用來啟動Activity。或透過broadcastIntent()把intent傳送到BroadcastReceiver中,並藉由startService(intent)與在背景執行的Service。
    Intent可以提供不同的application之間的聯繫,例如在一個activity中啟動另外一個activity,切換畫面也是用Intent來呼叫不同的畫面
    Intent常見的屬性有兩個,action以及category。action用來描述activity的的行為別,常見的值有MAIN or EDIT等。category是用來描述activity的類別,常見的值有LAUNCHER。 Intent的屬性可以寫在manifest.xml中的<intent filter>
    Intent在聯繫不同的activity時,可以透過putExtra傳遞需要互通的資料。
    google文件
  • Activity
    最常見的class,與使用者互動的視窗就是由這個類別負責,啟動activity會觸發onCreate(),離開activity時會觸發onPause()。activity的各個狀態可以參考activity lifecycle
  • Bundle
    一種類似hashtable的儲存結構,提供許多存取的method。當Intent傳遞資訊的時候,可以使用Bundle來封裝資料。
  • android.widget
    這個package裡面包含重要的外觀介面的元件,例如Button, TextView, RadioButton等。
  • 常見的layout
    有Absolutelayout, AdapterView, Framelayout, Linearlayout, mapView, Relativelayout等。都是繼承自android.view.viewGroup這個類別。

Thursday, February 5, 2009

android activity生命狀態

activity執行中會經過不同的狀態,例如啟動、暫停等。以下就不同的狀態會觸發的事件紀錄一下

  • onSaveInstanceState
    當activity因為記憶體不足時被android停止時就會觸發(此時onDestroy也會被觸發),或是使用者切換activity等 activity停止時也會觸發,會儲存目前的狀態。
  • onPause
    離開該activity時、設定改變(screen orientation, language, input devices)被觸發,但是該actiity仍存在記憶體中,尚未被釋放記憶體空間。
  • onResume
    由pause的狀態回復到執行的狀態被觸發,也就是目前使用者互動的狀態。
  • onCreate
    activity第一次被執行時會被觸發。
  • onStop
    離開該activity時、設定改變(screen orientation, language, input devices)被觸發
  • onDestroy
    離開該activity時、設定改變(screen orientation, language, input devices)被觸

Monday, February 2, 2009

aspx轉excel, word

Word
Response.AddHeader("content-disposition", "attachment;filename=KS-0-9602.doc")
Response.ContentType = "application/vnd.ms-word"

excel
Response.AddHeader ("Content-Disposition", "attachment; filename=KS-0-9602..xls")
Response.ContentType = "application/ms-excel"

加上 style="mso-number-format:" 以指定excel中資料的格式,以下把數字轉為文字
<td style="mso-number-format: @">0121111</td>

Thursday, January 22, 2009

進入android模擬器的console

andorid底層為linux核心,android則是架在linux上面的應用程式框架

1. 在eclispe執行android以開啟android emulator

2. windows中打開命令提示列  telnet localhost 5554 依照emulator打入不同的port號

3. 輸入help可看到android console提供的指令

Sunday, January 11, 2009

安裝android 開發環境

1.下載eclipse jee 3.41, android 1 R2, java SDK 6 update 11

2. 解壓縮eclipse jee 3.41, android 1 R2, 安裝java SDK 6 update 11

3. 在系統變數的path加入;<sdk_dir>/tools

4. 在eclipse中加入android的plug-in, plugin的網址為https://dl-ssl.google.com/android/eclipse或是直接下載ADT的壓縮檔

5. 在eclipse中window=>preference選 android 設定SDK location

6. 如果之前有安裝過eclipse,並安裝先前版本的JDK,還需要在window->preference選java->installed JREs 更改為JDK1.6

DDMS

1. 在eclipse右上角點選"Open persepctive"->other->DDMS,之後在啟動模擬之後,就可以在DDMS觀看狀況了

DDMS可以透過USB連上hardware device,需要安裝USB driver(android_usb_windows.zip)

android sample

1. eclipse中開新專案。開完,在專案中File-> import, 選General->File System,路徑設定為<sdk_dir>/samples/AmpDemos,即可。

2. 執行的時候可以在Run Configurations設定launch action為哪一隻程式碼

3. 如果出現Re-installation fail due to different application signature的錯誤訊息,可以在adroid-sdk底下的tools中執行"adb uninstall com.example.android.apis"。

March. 2011
1. updated 完 android sdk後,在Eclipse中執行AVD manager時出現"location of android sdk has not been set up in the preferences", 點選eclipse->preferences->android SDK location時出現"could not find folder'tools' inside sdk"

確定sdk以安裝,且設定安裝路徑後仍有此錯誤。在update ADT plugin for eclipse後,問題解決。所以SDK與ADT都需要一同更新。

Wednesday, December 10, 2008

在Https中建立WCF service

在web.config中設定相關字串

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IWGWCF" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Certificate" proxyCredentialType="None" realm="" />
<message clientCredentialType="Certificate" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>

<services>
<service behaviorConfiguration="ServiceBehavior" name="WGWCF">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWGWCF"
name="serverEnd" contract="IWGWCF" />
<host>
<baseAddresses>
<add baseAddress="https://17-00sf300-01/WGWS" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>

<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"
httpsGetUrl="https://17-00sf300-01/WGWS/" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="WGWCFBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"
httpsGetUrl="https://17-00sf300-01/WGWS/" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

WGWCF 使用session

在binding中設定好ReliableSession.enabled = True即可

 

另外在Contract中,可以設定SessionMode=SessionMode.Requied

[ServiceContract(Name = "IWGWCF", SessionMode = SessionMode.Required)]
public interface IWGWCF
{
[OperationContract]
string search(string keyword, int start, int returnCount);


}

在behavior中可以設定session使用的時間周期

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class WGWCF : IWGWCF
{
public string search(){

}
}