1 / 52

A n d r o i d b e g i n n i n g

A n d r o i d b e g i n n i n g. NCCU SSRC William Hong 洪維林 2009.12. Agenda. Basic concept History of Android Android Architecture Application fundamentals Application Components Setup Environment Preparing stuff( 需要的安裝檔案 & 簡要說明安裝程序 ) PDA Driver 安裝 Android SDK Directory

Download Presentation

A n d r o i d b e g i n n i n g

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android beginning NCCU SSRC William Hong 洪維林 2009.12

  2. Agenda • Basic concept • History of Android • Android Architecture • Application fundamentals • Application Components • Setup Environment • Preparing stuff(需要的安裝檔案&簡要說明安裝程序) • PDA Driver安裝 • AndroidSDK Directory • Google Market(自己開發的程式, 加入Market) • Let’s start coding • Android專案 : HelloCS • AndroidManifest.xml • UI Layout xml • U2ex architecture • Reference

  3. Basic Concept History of Android Android Architecture Application fundamentals Application Components

  4. ‘05/8:Google 收購Android公司, Google邁入mobile的世界Android公司, 原本即開發手機OS ‘07:開放手機聯盟成立 & 發布第一版 Android SDK ‘08:舉辦2008開發競賽 & Market上線 ’08/9/23:HTC G1上市 & Android 1.0 SDK release ’09/10:Android 2.0 SDK release History of Android

  5. Android Architecture 藍色: Java

  6. Applications • 包含內建的應用程式-聯絡人、eMail 、Map 、Calendar 、簡訊…等等 • 從Market下載的程式 • 自行開發的程式 • 以Java Programming Language開發

  7. Application Framework • Google提供API,此framework內已經具備多種不同的基礎軟體元件,在開發ap時,可直接使用 • 內容可參考網頁

  8. Libraries • Library以c/c++開發 • 屬系統元件, 開發者可以透過 Application Framework 來使用這些功能

  9. Android Runtime • Core Libraries • 對應於Java Programming Language • Dalvik Virtual Machine (簡稱 DVM) • 開發者: Dan Bornstein, 以某本小說中談論的冰島Dalvik命名 • 針對手機開發 • Run(綁) on Linux  Virtual Memory, multiple processes • 執行指令精簡(節省記憶體)&CPU效率(not JIT) • 詳細說明, 請看連結

  10. Linux Kernel • Base on Linux 2.6 • 已修改kernel, 以避免GPL授權問題(連結) • Linux 版權GNU General Public License version 2 (GPLv2) • Driver移動至linux userspace,硬體廠商不需要公開driver source • Power Management修改 • 針對手機環境 • 沒有使用, 就關掉

  11. Application fundamentals • 使用Java language開發 • 編譯完成, 以 tool/aapt.exe包裹為 .apk • Apk  application • 三種基本特性 • 每個application在自己的Linux process中執行 • 每個process有自己的Java VM, isolate from other applications • 每個application權限獨立分開, 不能讀取其他application的檔案 • 若兩個application具備相同的linux id, 即可以share VM & files (少用)

  12. Application Components • 在framework之上進行開發, 所以沒有main(), 且由framework主控全局 • 溝通橋樑:Intent • 四大元件:Android程式四大塊 • Activity • Service • Broadcast receiver • Content provider • 要明確定義於:AndroidManifest.xml

  13. Intent • 用來描述一個程式想要作些什麼事情 • 每個Intent都帶有一個動作(action),並根據不同的動作去行動 • 例 public void onClick(){ Uri uri = Uri.parse("http://www.nccu.com.tw/"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);} • 要開啟一個網頁, 由Android去決定誰要開網頁

  14. Activity • 包括UI, 以及與user互動 • 上面可以放button、list、picture、text… • UI可動態調整(增加、減少、換位置) • 透過intent跳轉至其他activity • 費時的程式要放到Service, handler…, 超過5秒, 會出現ANR(Android is Not Responding) • Life cycle最重要, 要記熟

  15. Activity life cycle • 啟動出現畫面 • onCreate() • onStart() • onResume() • 關閉畫面結束 • onPause() • onStop() • onDestroy()

  16. Activity life cycle

  17. Activity life cycle

  18. Activity life cycle

  19. Activity life cycle

  20. Service • 長時間於背景執行, 無UI畫面 • 可避免ANR的問題 • 例 • 播放音樂 • 背景接收網路訊息 • 壓縮or解壓縮檔案 • 利用bindService(), 讓Activity與Service溝通

  21. Service Life Cycle1 • 與Activity相似, 有些許差異 • onCreate and onStart differences • Services can be started when a client calls the Context.startService(Intent) method. If the service isn't already running, Android starts it and calls its onCreate method followed by the onStart method. If the service is already running, its onStart method is invoked again with the new intent. So it's quite possible and normal for a service's onStart method to be called repeatedly in a single run of the service.

  22. Service Life Cycle 2 • onResume, onPause, and onStop are not needed • Recall that a service generally has no user interface, so there isn't any need for the onPause, onResume, or onStop methods. Whenever a service is running, it is always in the background.

  23. Service Life Cycle 3 • onBind • If a client needs a persistent connection to a service, it can call the Context.bindService method. This creates the service if it is not running, and calls onCreate but not onStart. Instead, the onBind method is called with the client's intent, and it returns an IBind object that the client can use to make further calls to the service. It's quite normal for a service to have clients starting it and clients bound to it at the same time.

  24. Service Life Cycle 4 • onDestroy • As with an activity, the onDestroy method is called when the service is about to be terminated. Android will terminate a service when there are no more clients starting or bound to it. As with activities, Android may also terminate a service when memory is getting low. If that happens, Android will attempt to restart the service when the memory pressure passes, so if your service needs to store persistent information for that restart, it's best to do so in the onStart method.

  25. Broadcast Receiver • 監聽有興趣的Intent • 利用sendBroadcast()啟動一個廣播, 並附上對應參數 • 要於5sec.內完成 • 可啟動特定Activity or Service or 更新畫面 • 例 • Android系統於電力狀況有變動時, 傳遞一個電力廣播 • 若我們是一個電力容量顯示程式, 則可接收此廣播, 並顯示於畫面上, 或鈴聲, 或震動 • 連結

  26. Content Provider • 與其他程式分享資料 • 例 • 存取Contact • content://contacts/people/45 (傳回:聯絡人編號45的聯絡人記錄) • content://contacts/people/ (傳回:全部聯絡人) • 連結 • 連結2

  27. Setup Environment Preparing stuff PDA Driversetup AndroidSDK Directory Google Market

  28. Preparing stuff • JDK 6 • Eclipse 3.5.1 • Android SDK • ADTAndroidDeveloperTools

  29. 設定eclipse Menu/Window/Preference 選定Android sdk root dir

  30. 設定eclipse, 完成 新增專案, 可以選擇Android project即可

  31. PDAdriver安裝 Usb與pda連線

  32. PDAdriver安裝 挑選 sdk 的 usb_driver目錄

  33. PDAdriver安裝 安裝中

  34. PDAdriver安裝 完成, 可能需要重開機

  35. PDA連線設定 Settings Application Settings Development 三個項目要打勾

  36. 可將程式執行於PDA 完成連線, 且可以執行於PDA

  37. AndroidSDKDirectory Add-ons : 外加元件 Docs:sdk文件 Plateforms:各版sdk Tools : sdk 工具 Usb_driver :手機連usb工具

  38. Market1 建立帳號

  39. Market2 繳費 $25

  40. Market 3 可上傳自己的專案

  41. Market4 從pda market下載

  42. Let’s starting coding Android專案 : HelloCS AndroidManifest.xml UI Layout xml U2ex architecture Reference 42

  43. Android專案 : HelloCS

  44. Android專案 : HelloCS 專案目錄展開

  45. Android專案 : HelloCS 執行

  46. Android專案 : HelloCS 啟動 啟動simulator

  47. Android專案 : HelloCS 完成 執行結果

  48. AndroidManifest.xml • 定義此專案使用的Activity與其屬性

  49. UI Layout main.xml xml 編輯器 WYSWYG編輯器 可增加view more easy

  50. U2ex architecture

More Related