introduction to android
DESCRIPTION
Introduction to Android By Eng.Ahmed Mustafa Daoud At Google Camp event Organized by MUFIX CommunityTRANSCRIPT
![Page 1: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/1.jpg)
A Developer’s Introduction to Mobile computing &Google Android
Dr. Frank McCownHarding University
Fall 2011Edited by Ahmed Daoud
This work is licensed under Creative Commons Attribution-NonCommercial 3.0
![Page 2: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/2.jpg)
2
Why Mobile Computing?
• Mobile platform is the platform of the future– Double-digit growth in world-wide smartphone ownership3
• Job market is hot– Market for mobile software surges from $4.1 billion in 2009
to $17.5 billion by 20121
– 2010 Dice.com survey: 72% of recruiters looking for iPhone app developers, 60% for Android1
– Dice.com: mobile app developers made $85,000 in 2010 and salaries expected to rise2
• It’s a lot of fun!1 http://www.businessweek.com/technology/content/oct2010/tc20101020_639668.htm2 http://it-jobs.fins.com/Articles/SB129606993144879991/Mobile-App-Developers-Wanted-at-Ad-Agencies3http://www.gartner.com/it/page.jsp?id=1466313
![Page 3: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/3.jpg)
3
Smartphones
iPhone 4 LG Revolution HTC Trophy BlackBerry Curve
![Page 4: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/4.jpg)
4http://www.csectioncomics.com/2010/11/iphone-vs-android-vs-blackberry.html
![Page 5: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/5.jpg)
5
Tablets
Galaxy Tab 10.1
iPad 2
Acer Iconia Tab W500
![Page 6: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/6.jpg)
6http://www.androidauthority.com/nielsen-report-americans-use-tablets-smartphones-as-tv-buddies-14564/
Device Usage
![Page 7: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/7.jpg)
7
http://www.businessinsider.com/chart-of-the-day-smartphone-sales-to-beat-pc-sales-by-2011-2009-8
Smartphone vs. PC Sales
![Page 8: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/8.jpg)
8
http://www.infogenra.com/global-smartphone-sales-for-2011-pegged-at-420-million-units-infographic.html
Smartphone Market Share
![Page 9: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/9.jpg)
9
http://gigaom.com/apple/iphone-flat-in-u-s-as-android-takes-market-share-lead/
Top US Smartphone OS Platforms
![Page 10: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/10.jpg)
10
Mobile Devices: Advantages
• Always with the user• Typically have Internet access• Typically GPS enabled• Typically have accelerometer & compass• Typically have cameras & microphones• Apps are free or low-cost
![Page 11: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/11.jpg)
11
Mobile Devices: Disadvantages
• Limited screen size• Limited battery life• Limited processor speed• Limited and sometimes slow network access• Limited or awkward input: soft keyboard, phone
keypad, touch screen, or stylus• Limited web browser functionality• Range of platforms & configurations across
devices
![Page 12: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/12.jpg)
12
Mobile Applications
• What are they?– Any application that runs on a mobile device
• Types– Web apps: run in a web browser• HTML, JavaScript, Flash, server-side components, etc.
– Native: compiled binaries for the device• Economics– Free (often ad-supported) vs. paid
![Page 13: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/13.jpg)
13
Free vs. PaidApps
http://backtogeek.com/2011/04/27/there-are-now-more-free-apps-for-android-than-for-the-iphone-distimo/
![Page 14: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/14.jpg)
14
Popular Development Environments
• Java ME • .NET Compact Framework (C++, C#, VB.NET) for
Windows Mobile• Windows Phone 7 (Silverlight and XNA)• Qualcomm’s BREW (C or C++)• Symbian (C++)• BlackBerry (Java)• Android (Java)• iPhone (Objective-C)• Is having so many choices a good thing?
![Page 15: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/15.jpg)
15
xCode IDE & iPhone Emulator
http://developer.apple.com/iphone/library/referencelibrary/GettingStarted/Creating_an_iPhone_App/index.html
![Page 16: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/16.jpg)
16
Eclipse and Android Emulator
![Page 17: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/17.jpg)
17
Brief History
• 2005– Google acquires startup Android Inc. to start Android platform– Work on Dalvik VM begins
• 2007– Open Handset Alliance announced– Early look at SDK
• 2008– Google sponsors 1st Android Developer Challenge– T-Mobile G1 announced– SDK 1.0 released– Android released open source (Apache License)– Android Dev Phone 1 released
Pro Android by Hashimi & Komatineni (2009)
![Page 18: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/18.jpg)
18
Brief History cont.
• 2009– SDK 1.5 (Cupcake)
• New soft keyboard with “autocomplete” feature
– SDK 1.6 (Donut)• Support Wide VGA
– SDK 2.0/2.0.1/2.1 (Eclair)• Revamped UI, browser
• 2010– Nexus One released to the public– SDK 2.2 (Froyo)
• Flash support, tethering
– SDK 2.3 (Gingerbread)• UI update, system-wide copy-paste
![Page 19: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/19.jpg)
19
Brief History cont.
• 2011– SDK 3.0 (Honeycomb) for tablets only• New UI for tablets, support multi-core processors
– SDK 3.1 and 3.2 • Hardware support and UI improvements
– SDK 4.0 (Ice Cream Sandwich) • For Q4, combination of Gingerbread and Honeycomb
![Page 20: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/20.jpg)
http://www.robotbriefs.com/news/2010/9/7/catch-up-on-android-history-with-an-infographic.html
![Page 21: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/21.jpg)
What is Google Android?
• A software stack for mobile devices that includes– An operating system– Middleware– Key Applications
• Uses Linux to provide core system services– Security– Memory management– Process management– Power management– Hardware drivers
![Page 22: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/22.jpg)
http://developer.android.com/guide/basics/what-is-android.html
![Page 23: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/23.jpg)
Setup Development Environment
• Install JDK 5, 6, or 7• Install Eclipse IDE for Java EE Developers
(version 3.7 - Indigo)• Download and unpack the Android SDK • Install Android Development Tools (ADT) plugin
for Eclipse• Detailed install instructions available on
Android sitehttp://developer.android.com/sdk/installing.html
![Page 24: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/24.jpg)
24
![Page 25: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/25.jpg)
25
Android Emulator or AVD
• Emulator is essential to testing app but is not a substitute for a real device
• Emulators are called Android Virtual Devices (AVDs)
• Android SDK and AVD Manager allows you to create AVDs that target any Android API level
• AVD have configurable resolutions, RAM, SD cards, skins, and other hardware
![Page 26: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/26.jpg)
26
Android Emulator: 1.6 Device
![Page 27: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/27.jpg)
27
Android Emulator: 2.2 Device
![Page 28: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/28.jpg)
28
Android Emulator: 3.0 Device
![Page 29: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/29.jpg)
29
Emulator Basics
• Host computer’s keyboard works• Host’s mouse works like finger• Uses host’s Internet connection• Side buttons work: Home, Menu, Back, Search,
volume up and down, etc. • Ctrl-F11 toggle landscape portrait• Alt-Enter toggle full-screen mode• More info at
http://developer.android.com/guide/developing/devices/emulator.html
![Page 30: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/30.jpg)
30
Emulator Limitations• No support for placing or receiving actual phone calls
– Simulate phone calls (placed and received) through the emulator console• No support for USB connections• No support for camera/video capture (input)• No support for device-attached headphones• No support for determining connected state• No support for determining battery charge level and AC charging state• No support for determining SD card insert/eject• No support for Bluetooth• No support for simulating the accelerometer
– Use OpenIntents’s Sensor Simulator
![Page 31: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/31.jpg)
31
In other words, test your app on an actual device!
![Page 32: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/32.jpg)
32
Create an AVD using Android SDK and AVD Manager
![Page 33: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/33.jpg)
33
Or From the Command Line
C:\android-sdk-windows\tools>android create avd -n MyDevice -t android-8Android 2.2 is a basic Android platform.Do you wish to create a custom hardware profile [no]Created AVD 'MyDevice2' based on Android 2.2,with the following hardware config:hw.lcd.density=240vm.heapSize=24
C:\android-sdk-windows\tools>emulator -avd MyDevice
Device name
Target platform
More info: http://developer.android.com/guide/developing/devices/managing-avds-cmdline.html
Launch device
![Page 34: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/34.jpg)
Android Runtime: Dalvik VM
• Subset of Java developed by Google• Optimized for mobile devices (better memory
management, battery utilization, etc.)• Dalvik runs .dex files that are compiled
from .class files• Introduces some new libraries• Does not support some Java libraries like AWT
![Page 35: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/35.jpg)
Applications Are Boxed
• By default, each app is run in its own Linux process– Process started when app’s code needs to be executed– Threads can be started to handle time-consuming
operations• Each process has its own Dalvik VM• By default, each app is assigned unique Linux ID– Permissions are set so app’s files are only visible to that
app
![Page 36: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/36.jpg)
Producing an Android App
Java code Byte code
Dalvik exe
Byte code <xml>
<str>
.java .class
Other .class files
javac
dx
classes.dex
AndroidManifest.xml
Resources
.apk
aapt
![Page 37: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/37.jpg)
Hello Android Tutorial
http://developer.android.com/resources/tutorials/hello-world.html
![Page 38: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/38.jpg)
38
Important Files• src/HelloAndroid.java
– Activity which is started when app executes• res/layout/main.xml
– Defines & lays out widgets for the activity• res/values/strings.xml
– String constants used by app• gen/R.java (Don’t touch!)
– Auto-generated file with identifiers from main.xml, strings.xml, and elsewhere
• AndroidManifest.xml– Declares all the app’s components– Names libraries app needs to be linked against– Identifies permissions the app expects to be granted
![Page 39: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/39.jpg)
39
src/HelloAndroid.java
• Activity which is started when app executes
![Page 40: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/40.jpg)
40
res/layout/main.xml
• Declares layouts & widgets for the activity
Tree from: http://developer.android.com/guide/topics/ui/index.html
![Page 41: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/41.jpg)
41
Various Layouts
http://developer.android.com/resources/tutorials/views/index.html
![Page 42: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/42.jpg)
42
Various Widgets
http://developer.android.com/resources/tutorials/views/index.html
![Page 43: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/43.jpg)
43
res/values/strings.xml
• String constants used by app
• Used for supporting Localization – res/values-es/values/strings.xml to support Spanish– res/values-fr/values/strings.xml to support French– Etc.
![Page 44: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/44.jpg)
44
gen/R.java
• Auto-generated file with identifiers from main.xml, strings.xml, and elsewhere
Do not modify!
![Page 45: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/45.jpg)
45
AndroidManifest.xml
• Declares all the app’s components• Names libraries app needs to be linked against• Identifies permissions the app expects to be granted
![Page 46: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/46.jpg)
46
Four Application Components
1. Activities– Presents a visual UI for a single endeavor– Single app may be composed of several activities– Examples: list of photos, buttons to start/stop a song
2. Services– Performs background work (no UI)– Examples: play background music, retrieve data over a network
3. Broadcast Receivers– Receives and reacts to broadcast announcements (no UI)– Broadcast examples: battery is low, pic is taken, lang pref changed
4. Content Providers– Provides app data to other applications (no UI)– Examples: share contact info from SQLite, image from the file system
![Page 47: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/47.jpg)
SDK Samples
![Page 48: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/48.jpg)
Activity Lifecycle
http://developer.android.com/reference/android/app/Activity.html
![Page 49: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/49.jpg)
Thank youAny Question?
![Page 50: Introduction to Android](https://reader033.vdocuments.site/reader033/viewer/2022051613/54c8068b4a79593e098b45d2/html5/thumbnails/50.jpg)
References
• Android Introduction by Marko Gargenta, http://www.lecturemaker.com/2009/10/android-software-platform/
• Android Dev Guide http://developer.android.com/guide/topics/fundamentals.html
• Pro Android by Hashimi & Komatineni (2009)