Android In A Nutshell

7,951 views

Published on

My introduction to Android.

Published in: Technology
0 Comments
19 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,951
On SlideShare
0
From Embeds
0
Number of Embeds
586
Actions
Shares
0
Downloads
0
Comments
0
Likes
19
Embeds 0
No embeds

No notes for slide

Android In A Nutshell

  1. 1. Ted Chien Supervisory Engineer viWave Co. Ltd. LinkedIn: http://www.linkedin.com/in/htchien
  2. 2. <ul><li>Android Introduction </li></ul><ul><ul><li>The Platform </li></ul></ul><ul><ul><li>Google Mobile Service </li></ul></ul><ul><ul><li>SDKs </li></ul></ul><ul><ul><li>Tools </li></ul></ul><ul><li>Application Fundamentals </li></ul><ul><li>Q&A </li></ul>
  3. 3. <ul><li>An open source, freely Linux-based software stack for mobile devices. </li></ul><ul><li>Code license: Apache License </li></ul><ul><li>Including: </li></ul><ul><ul><li>Operating System </li></ul></ul><ul><ul><ul><li>Use Linux as base </li></ul></ul></ul><ul><ul><li>Middlewares </li></ul></ul><ul><ul><ul><li>Libraries, Dalvik VM, etc. </li></ul></ul></ul><ul><ul><li>Application Framework </li></ul></ul><ul><ul><ul><li>Java layer; provides system services. </li></ul></ul></ul><ul><ul><li>Key Applications </li></ul></ul><ul><ul><ul><li>Home, Browser, Calendar, Contacts, Phone, etc. </li></ul></ul></ul>
  4. 5. <ul><li>Linux Kernel </li></ul><ul><ul><li>Use Linux 2.6 for core system services. </li></ul></ul><ul><ul><li>Provides a layer between the hardware and the software stack. </li></ul></ul>
  5. 6. <ul><li>Libraries </li></ul><ul><ul><li>System C Libraries </li></ul></ul><ul><ul><ul><li>Heavily modified BSD C libraries. </li></ul></ul></ul>
  6. 7. <ul><li>Libraries </li></ul><ul><ul><li>Media Framework </li></ul></ul><ul><ul><ul><li>Based on PacketVideo OpenCORE, supports AAC, AMR, H.263, MP3, MPEG-4, JPG, PNG. </li></ul></ul></ul><ul><ul><ul><li>Also supports VC-1 to playback Windows Media 9 files. </li></ul></ul></ul><ul><ul><ul><li>Advanced framework with simple Java API layer. </li></ul></ul></ul>
  7. 8. <ul><li>Libraries </li></ul><ul><ul><li>Surface Manager : system-wide renderer, manage display system. </li></ul></ul><ul><ul><li>LibWebCore : web browser engine (from WebKit). </li></ul></ul><ul><ul><li>SGL : Skia Graphics Library, for 2D Graphics. </li></ul></ul><ul><ul><li>3D Libraries : based on OpenGL ES 1.1. </li></ul></ul><ul><ul><li>FreeType : font libraries. </li></ul></ul><ul><ul><li>SQLite : data base engine. </li></ul></ul>
  8. 9. <ul><li>Runtime </li></ul><ul><ul><li>Java Core Libraries </li></ul></ul><ul><ul><li>Dalvik VM </li></ul></ul>
  9. 10. <ul><li>Dalvik VM </li></ul><ul><ul><ul><li>Customized Java-compatible VM. </li></ul></ul></ul><ul><ul><ul><li>Runs optimized file format (.dex) </li></ul></ul></ul><ul><ul><ul><li>Also run unmodified Java .class / .jar files. </li></ul></ul></ul><ul><ul><ul><li>Designed for embedded system </li></ul></ul></ul><ul><ul><ul><ul><li>Use memory efficiently. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Highly CPU-optimized bytecode interpreter. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Supports multiple VM processes per device. </li></ul></ul></ul></ul>
  10. 11. <ul><li>Dalvik VM </li></ul><ul><ul><li>Cache applications in .dex format to speed up loading. </li></ul></ul><ul><ul><ul><li>Transformed from Java .class file. </li></ul></ul></ul><ul><ul><ul><li>Stored in data partition, might generated multiple times. </li></ul></ul></ul><ul><ul><li>In GEP build, applications are run in .odex format. </li></ul></ul><ul><ul><ul><li>Optimized DEX format, compressed to have smaller size. </li></ul></ul></ul><ul><ul><ul><li>Stored in system image, only generated once. </li></ul></ul></ul><ul><ul><li>Relies on Linux kernel for threading and low level memory management. </li></ul></ul>
  11. 12. <ul><li>Application Framework </li></ul><ul><ul><li>Provides framework APIs, a sets of services and systems. </li></ul></ul><ul><ul><li>More: Sensor Manager, Power Manager, Search Manager, etc. </li></ul></ul>
  12. 13. <ul><li>Applications </li></ul><ul><ul><li>Java applications written by engineers to support different use. </li></ul></ul>
  13. 14. <ul><li>Google Experience Phone (GEP) </li></ul><ul><ul><li>Has “with Google” logo. </li></ul></ul><ul><ul><li>Has Google Mobile apps. </li></ul></ul><ul><ul><li>Totally controlled by Google, made by Google. </li></ul></ul><ul><li>Vendor Experience Phone (HEP, MEP, etc) </li></ul><ul><ul><li>No “with Google” logo. </li></ul></ul><ul><ul><li>Must pass Google verification. </li></ul></ul><ul><ul><li>Have Google Mobile apps. </li></ul></ul><ul><ul><li>Vendors can add their own bonus applications. </li></ul></ul><ul><li>Open Source Phone </li></ul><ul><ul><li>No “with Google” logo. </li></ul></ul><ul><ul><li>No Google Mobile apps. </li></ul></ul>
  14. 15. <ul><li>Setup Wizard </li></ul><ul><ul><li>Provides OOBE setup. </li></ul></ul><ul><ul><li>Login user to Gmail so device can sync data from Google online services. </li></ul></ul><ul><li>Gmail </li></ul><ul><ul><li>With Contact Info. </li></ul></ul><ul><li>Google Calendar </li></ul><ul><li>Google Talk </li></ul><ul><li>Google Maps </li></ul><ul><ul><li>With Navigation in 2.0 </li></ul></ul><ul><li>YouTube </li></ul><ul><li>Android Market </li></ul>
  15. 16. <ul><li>Similar to Apple App Store. </li></ul><ul><li>Can download free / paid apps. </li></ul><ul><li>Add preview images in Android 1.6. </li></ul><ul><li>Filter applications by API level defined in the applications. </li></ul><ul><li>Share revenue with developers and telecom operators: </li></ul><ul><ul><li>Developer: 70% </li></ul></ul><ul><ul><li>Telecom Operator: 30% </li></ul></ul><ul><li>http://market.android.com </li></ul>
  16. 17. <ul><li>ROM images </li></ul><ul><ul><li>hboot.img : low level boot loader. </li></ul></ul><ul><ul><li>radio.img : radio code. </li></ul></ul><ul><ul><li>boot.img : Linux kernel. </li></ul></ul><ul><ul><li>system.img : Android framework, system applications / libraries, etc. </li></ul></ul><ul><ul><li>recovery.img : used to recovery / upgrade Android system. </li></ul></ul><ul><ul><li>userdata.img : user-specific data or user applications downloaded from Android Market. </li></ul></ul>
  17. 18. <ul><li>Needs to work with ADT (Android Developer Toolkit) and Eclipse </li></ul><ul><li>Has following contents: </li></ul><ul><ul><li>Emulator images (with Dream skin). </li></ul></ul><ul><ul><li>Development tools </li></ul></ul><ul><ul><ul><li>AVD: Android Virtual Device </li></ul></ul></ul><ul><ul><ul><li>DDMS: Dalvik Debug Monitor Service </li></ul></ul></ul><ul><ul><li>Has sample programs. </li></ul></ul><ul><ul><li>Has documentations. </li></ul></ul>
  18. 19. <ul><li>Supports all mainstream OS </li></ul><ul><ul><li>Linux (Ubuntu 8.04 LTS suggested) </li></ul></ul><ul><ul><li>Mac OS X Leopard </li></ul></ul><ul><ul><li>Windows XP / Vista </li></ul></ul><ul><li>Requires Eclipse 3.3 or later. </li></ul>
  19. 20. <ul><li>ADT: Android Developer Toolkit </li></ul><ul><ul><li>Need to work in Eclipse IDE. </li></ul></ul><ul><ul><li>Integrated with AVD Manager. </li></ul></ul><ul><ul><li>Integrated with DDMS. </li></ul></ul><ul><ul><li>Has WYSWYG UI Designer. </li></ul></ul><ul><ul><li>Has Create Project Wizard. </li></ul></ul><ul><ul><li>Has code / XML editor. </li></ul></ul><ul><ul><li>Easy to write / build / debug Java code and get log. </li></ul></ul>
  20. 21. <ul><li>ADT + SDK: </li></ul><ul><ul><li>Only can write / debug Java codes for Framework and Applications. </li></ul></ul><ul><ul><li>No support for native code (C/C++) applications. </li></ul></ul><ul><ul><ul><li>For native code applications, we need to use commands to manually build and use GNU Debugger to debug under shell console. </li></ul></ul></ul><ul><ul><li>Can only integrate with Eclipse IDE. </li></ul></ul>
  21. 22. <ul><li>Where to download the SDK? </li></ul><ul><ul><li>http://developer.android.com/sdk/ </li></ul></ul><ul><li>Where to download ADT? </li></ul><ul><ul><li>Download via Android.com: </li></ul></ul><ul><ul><ul><li>http://developer.android.com/sdk/eclipse-adt.html </li></ul></ul></ul><ul><ul><li>Download within Eclipse IDE: </li></ul></ul><ul><ul><ul><li>Help->Install New Software. </li></ul></ul></ul><ul><ul><ul><li>Download URL: https://dl-ssl.google.com/android/eclipse/ </li></ul></ul></ul><ul><li>After download and install ADT, need to set SDK location in Window ->Preference->Android. </li></ul>
  22. 23. <ul><li>An developer challenge that Google hold every year. </li></ul><ul><li>For Android mobile platform. </li></ul><ul><li>Demonstrates the capabilities of each Android platform. </li></ul><ul><li>http://code.google.com/android/adc </li></ul>
  23. 24. <ul><li>See http://developer.android.com/guide/developing/tools/ </li></ul><ul><li>fastboot </li></ul><ul><ul><li>Tool used to detect devices. </li></ul></ul><ul><ul><li>Can flash Android ROM images to device. </li></ul></ul><ul><ul><li>Can write specific oem data to low level boot loader. </li></ul></ul><ul><li>adb (Android Debug Bridge) </li></ul><ul><ul><li>Communication protocol between PC and device. </li></ul></ul><ul><ul><li>Tool to send / receive data between PC and device. </li></ul></ul>
  24. 25. <ul><li>Android Native Development Kit </li></ul><ul><li>Use shell commands to build C/C++ libraries and Java applications for the Android platform. </li></ul><ul><li>Can embedded native code libraries (.so) into .apk file for easy deployment. </li></ul><ul><li>Provides following native libraries: </li></ul><ul><ul><li>libc, libm, JNI interface, libz, liblog, OpenGL ES 1.1, minimal set of C++ headers. </li></ul></ul><ul><li>Where to download: http://developer.android.com/sdk/ndk/ </li></ul>
  25. 26. <ul><li>Application </li></ul><ul><li>Activity & Task </li></ul><ul><li>Service </li></ul><ul><li>Intent & IntentFilter </li></ul><ul><li>Broadcast Receiver </li></ul><ul><li>Content Provider </li></ul>
  26. 27. <ul><li>Application = Android Project in Eclipse = .apk (Android Package) </li></ul><ul><li>Packed by aapt tool. </li></ul><ul><li>Has following main building blocks: </li></ul><ul><ul><li>Activity </li></ul></ul><ul><ul><li>ContentProvider </li></ul></ul><ul><ul><li>IntentReceiver </li></ul></ul><ul><ul><li>Service </li></ul></ul>
  27. 28. <ul><li>Defines the API Level used in the application. </li></ul><ul><ul><li>Android Market will filter applications based on the API Level defined. </li></ul></ul>
  28. 29. <ul><li>One application will have only one AndroidManifest.xml. </li></ul><ul><ul><li>Declare permissions that are required to use protected API or interact with applications. </li></ul></ul><ul><li>Describes the resources the application can use. </li></ul>
  29. 30. <ul><li>List all components used in the application. </li></ul><ul><li>Describes capabilities and behaviors of each component. </li></ul><ul><li>Lists the libraries that application must be linked with. </li></ul>
  30. 31. <ul><li>Each application runs in its own Linux process. </li></ul><ul><ul><li>Each process has its own Java VM. </li></ul></ul><ul><ul><li>Each process has an unique Linux user ID to access resources. </li></ul></ul><ul><ul><li>Activities / Services with the same user ID can run in the same process and share Java VM. </li></ul></ul><ul><li>Processes are started / stopped as needed to run an application’s components. </li></ul><ul><li>Process might be killed by system to reclaim resources. </li></ul>
  31. 32. <ul><li>Activites, IntentReceivers, Services run in the main thread </li></ul><ul><ul><li>Can start other threads if needed. </li></ul></ul><ul><li>ContentProviders are always multi-threaded. </li></ul>
  32. 33. <ul><li>Represents a window that we can place UI on. </li></ul><ul><ul><li>Can be embedded. </li></ul></ul><ul><ul><li>Can be faceless. </li></ul></ul><ul><ul><li>Can be in a floating window. </li></ul></ul><ul><ul><li>Can return a value. </li></ul></ul>
  33. 34. <ul><li>Defined in AndroidManifest.xml with <activity> tags. </li></ul><ul><li>An application can have one or more activities. </li></ul><ul><li>One activity can invoke other activities, even not in the same application. </li></ul><ul><li>One activity can be replaced by an activity in other application with the same Intent action. </li></ul>
  34. 35. <ul><li>Task: a group of activities, arranged in stack. </li></ul><ul><ul><li>Root activity: beginning of a task. </li></ul></ul><ul><ul><li>Top activity: current running activity in a task. </li></ul></ul><ul><ul><li>Activity can start new activity and push the old one into stack. </li></ul></ul><ul><ul><li>Press on BACK key will pop the old activity back to screen. </li></ul></ul>
  35. 37. <ul><li>Defined in AndroidManifest.xml with <service> tags. </li></ul><ul><li>An activity that has no UI but runs in background for infinite period of time. </li></ul><ul><ul><li>Ex: music player, network download, etc. </li></ul></ul><ul><li>It runs in the main thread of the process. </li></ul><ul><ul><li>Can run not only in its process but also in other application’s process. </li></ul></ul><ul><ul><li>For CPU intensive / block resource services, suggested to run threads in the service. </li></ul></ul>
  36. 39. <ul><li>An object that holds the content of a message: </li></ul><ul><ul><li>action : requested operation to perform. </li></ul></ul><ul><ul><ul><li>ACTION_VIEW, ACTION_PICK, etc. </li></ul></ul></ul><ul><ul><li>data : data to perform with, described as URI. </li></ul></ul><ul><ul><ul><li>URI: Uniform Resource Identifier. </li></ul></ul></ul><ul><ul><li>category : the intent belongs to which intent group. </li></ul></ul><ul><ul><li>type : MIME type to handle with. </li></ul></ul><ul><ul><li>extras : other customized application data. </li></ul></ul>
  37. 40. <ul><li>Match activities in the application against an intent. </li></ul><ul><li>Defined in AndroidManifest.xml , using < intent-fliter> tags. </li></ul><ul><li>Or defined in Activity.onResume() with BroadcastReciever . </li></ul>
  38. 41. <ul><li>Android can broadcast an intent to all activities in the system, and activities can receive broadcasted intents by registering BroadcastReceiver . </li></ul>
  39. 42. <ul><li>The way to register an broadcast intent: </li></ul><ul><ul><li>Define the intent with <receiver> tags in AndroidManifest.xml . </li></ul></ul><ul><ul><li>Register BroadcastReceiver in OnResume() and unregister it in OnPause() in an activity . </li></ul></ul><ul><li>Example: SD card handling in Gallery. </li></ul>
  40. 43. <ul><li>Provide uniform APIs to access data, and then provide to multiple applications through ContentResolver . </li></ul><ul><li>All content is represented by URIs. </li></ul>
  41. 44. <ul><li>ContentProvider </li></ul><ul><ul><li>defines how the data is stored in SQLite database in the system for different types of content. </li></ul></ul><ul><ul><li>has its own URI path </li></ul></ul><ul><ul><ul><li>content://contacts/1/phones </li></ul></ul></ul><ul><ul><li>maps URIs to different MIME types </li></ul></ul><ul><ul><ul><li>content://media/… -> JPG, PNG, etc. </li></ul></ul></ul>
  42. 45. <ul><li>ContentResolver </li></ul><ul><ul><li>defines how to access the data via URI from the database. </li></ul></ul><ul><li>Cursor </li></ul><ul><ul><li>defines how to access the sorted data set after query via ContentResolver . </li></ul></ul><ul><ul><li>Can be bound to ListView, GridView, Gallery, Spinner for displaying data. </li></ul></ul>
  43. 46. <ul><li>Google Android 手機應用程式入門,文魁出版社 , Taiwan </li></ul><ul><ul><li>Android 1.1~1.5 </li></ul></ul><ul><li>Google Android SDK 開發範例大全,悅知文化 , Taiwan </li></ul><ul><ul><li>Android 1.1~1.5 </li></ul></ul><ul><li>Busy Coder’s Guide to Android Development, CommonsWare, Mark Murphy, USA </li></ul><ul><ul><li>Android 1.1~2.0 </li></ul></ul><ul><li>Busy Coder’s Guide to Advanced Android Development, CommonsWare, Mark Murphy, USA </li></ul><ul><ul><li>Andorid 1.1~2.0 </li></ul></ul>

×