Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Bootcamp 2012

marakana
February 06, 2012

Android Bootcamp 2012

The definitive guide to understanding Android Application development. Check out the accompanying videos at http://shar.es/fxgx4

marakana

February 06, 2012
Tweet

More Decks by marakana

Other Decks in Education

Transcript

  1. Marko Gargenta
    marakana.com
    ANDROID  
    OVERVIEW  

    View full-size slide

  2. About  Marko  Gargenta
     
    Developer of Android Bootcamp for Marakana.
    Instructor for 1,000s of developers on Android at
    Qualcomm, Cisco, Motorola, DoD and other great orgs.
    Author of Learning Android published by O’Reilly.
    Speaker at OSCON (3x), ACM, IEEE, SDC, AnDevCon.
    Co-Founder of SFAndroid.org
    Co-Chair of Android Open conference:
    AndroidOpen.com

    View full-size slide

  3. Agenda
     
    •  Android  Then  &  Now  
    •  Android  versions  
    •  The  Stack  
    •  Opera•  Hello  World!  
    •  Main  Building  Blocks  
    •  Architec•  Android UI
    •  Debugging & Logging
    •  Android  Security  
    •  Summary  

    View full-size slide

  4. ANDROID  THEN  &  NOW
     

    View full-size slide

  5. History  and  Possible  Future
     
    2005   Google  buys  Android,  Inc.  
    Work  on  Dalvik  starts  
    2007   Open  Handset  Alliance  announced  
    Early  SoOware  Development  Kit  
    2008-­‐2010   Android  becomes  the  dominant  
    mobile  plaTorm  
    2011   Games,  Tablets,  TVs  
    Future?   Beyond  phones  

    View full-size slide

  6. Vision  for  Android
     
    Our goal is not just a single device. Our
    vision is a mobile platform that runs on
    many many different devices.
    – Eric Schmidt

    View full-size slide

  7. PlaTorm  Versions
     
    Version   API  Level   Nickname  
    Android  1.0   1   Android  
    Android  1.1   2   Android  
    Android  1.5   3   Cupcake  
    Android  1.6   4   Donut  
    Android  2.0   5   Éclair  
    Android  2.01   6   Éclair  
    Android  2.1   7   Éclair  
    Android  2.2   8   FroYo  
    Android  2.3   9   Gingerbread  
    Android  2.3.3   10   Gingerbread  
    Android  3.x   11,  12,  13   Honeycomb  
    Android  4.0   14   Ice  Cream  Sandwich  

    View full-size slide

  8. Version  Distribu  
    Source: Android.com

    View full-size slide

  9. Historical  Distribu  
    Source: Android.com

    View full-size slide

  10. Add-­‐Ons
     
    TouchWiz   MotoBlur  
    SenseUI  

    View full-size slide

  11. “With  Google”
     
    Devices that have “with Google” add-on feature a set of Google’s proprietary
    applications, such as Maps, Gmail, Gtalk, and many others.
    OEMs and carriers typically enter into a licensing agreement with Google in
    order to distribute Google version of Android.

    View full-size slide

  12. ANDROID  STACK  

    View full-size slide

  13. The  Stack  
    Linux Kernel
    Libraries
    Application Framework
    Applications
    Home Contacts Phone Browser Other
    Activity
    Manager
    Window
    Manager
    Content
    Providers
    View
    System
    Package
    Manager
    Telephony
    Manager
    Resource
    Manager
    Location
    Manager
    Notiication
    Manager
    Surface
    Manager
    OpenGL
    SGL
    Media
    Framework
    FreeType
    SSL
    SQLite
    WebKit
    libc
    Android Runtime
    Core Libs
    Dalvik
    VM
    Display
    Driver
    Keypad
    Driver
    Camera
    Driver
    WiFi
    Driver
    Flash
    Driver
    Audio
    Driver
    Binder
    Driver
    Power
    Mgmt

    View full-size slide

  14. Linux  Kernel  
    Android runs on Linux.
    Linux provides:
    Hardware abstraction layer
    Memory management
    Process management
    Networking
    Users never see Linux sub system
    The adb shell command opens
    Linux shell
    Linux Kernel
    Libraries
    Application Framework
    Applications
    Home Contacts Phone Browser Other
    Activity
    Manager
    Window
    Manager
    Content
    Providers
    View
    System
    Package
    Manager
    Telephony
    Manager
    Resource
    Manager
    Location
    Manager
    Notiication
    Manager
    Surface
    Manager
    OpenGL
    SGL
    Media
    Framework
    FreeType
    SSL
    SQLite
    WebKit
    libc
    Android Runtime
    Core Libs
    Dalvik
    VM
    Display
    Driver
    Keypad
    Driver
    Camera
    Driver
    WiFi
    Driver
    Flash
    Driver
    Audio
    Driver
    Binder
    Driver
    Power
    Mgmt
    Android™ Stack

    View full-size slide

  15. NaPieces borrowed from other
    open source projects:
    Bionic, a super fast and small
    license-friendly libc library optimized
    for Android
    WebKit library for fast HTML
    rendering
    OpenGL for graphics
    Media codecs offer support for
    major audio/video codecs
    SQLite database
    Much more…
    Linux Kernel
    Libraries
    Application Framework
    Applications
    Home Contacts Phone Browser Other
    Activity
    Manager
    Window
    Manager
    Content
    Providers
    View
    System
    Package
    Manager
    Telephony
    Manager
    Resource
    Manager
    Location
    Manager
    Notiication
    Manager
    Surface
    Manager
    OpenGL
    SGL
    Media
    Framework
    FreeType
    SSL
    SQLite
    WebKit
    libc
    Android Runtime
    Core Libs
    Dalvik
    VM
    Display
    Driver
    Keypad
    Driver
    Camera
    Driver
    WiFi
    Driver
    Flash
    Driver
    Audio
    Driver
    Binder
    Driver
    Power
    Mgmt

    View full-size slide

  16. Dalvik  
    Dalvik VM is Android implementation of
    Java VM
    Dalvik is optimized for mobile devices:
    •  Battery consumption
    •  CPU capabilities
    Key Dalvik differences:
    •  Register-based versus stack-based VM
    •  Dalvik runs .dex files
    •  More efficient and compact implementation
    •  Different set of Java libraries than JDK

    View full-size slide

  17. Applica  
    The rich set of system services
    wrapped in an intuitive Java API.
    This ecosystem that developers
    can easily tap into is what makes
    writing apps for Android easy.
    Location, web, telephony, WiFi,
    Bluetooth, notifications, media,
    camera, just to name a few.
    Linux Kernel
    Libraries
    Application Framework
    Applications
    Home Contacts Phone Browser Other
    Activity
    Manager
    Window
    Manager
    Content
    Providers
    View
    System
    Package
    Manager
    Telephony
    Manager
    Resource
    Manager
    Location
    Manager
    Notiication
    Manager
    Surface
    Manager
    OpenGL
    SGL
    Media
    Framework
    FreeType
    SSL
    SQLite
    WebKit
    libc
    Android Runtime
    Core Libs
    Dalvik
    VM
    Display
    Driver
    Keypad
    Driver
    Camera
    Driver
    WiFi
    Driver
    Flash
    Driver
    Audio
    Driver
    Binder
    Driver
    Power
    Mgmt

    View full-size slide

  18. ApplicaDalvik Executable + Resources = APK
    Must be signed (but debug key is okay
    for development)
    Many markets with different policies

    View full-size slide

  19. App  Distribu  
    •  One  of  the  markets  
    •  Side  loading  
    •  Internal  app  directory  

    View full-size slide

  20. Markets
     
    •  Google  Android  Market  
    •  Amazon  Android  Market  
    •  Other  emerging  markets  

    View full-size slide

  21. Side  Loading
     

    View full-size slide

  22. Internal  App  Directory
     

    View full-size slide

  23. OPERATING  SYSTEM  FEATURES    

    View full-size slide

  24. Mul  
    AudioPlayer lets you simply specify
    the audio resource and play it.
    VideoView is a View that you can
    drop anywhere in your activity, point
    to a video file and play it.
    XML:
    android:id="@+id/video"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center” />
    Java:
    player = (VideoView) findViewById(R.id.video);
    player.setVideoPath("/sdcard/samplevideo.3gp");
    player.start();

    View full-size slide

  25. Supported  Media  Formats
     
    Audio   AAC  LC/LTP,  HE-­‐AACv1  (AAC+),  HE-­‐
    AACv2,  AMR-­‐NB,  AMR-­‐WB,  MP3,  
    MIDI,  RTTTL/RTX,  Ogg,  PCM/WAVE  
    Video   H.263,  H.264,  MPEG-­‐4,  VP8  
    Image   JPEG,  GIF,  PNG,  BMP  
    RTSP and HTTP progressive streaming.
    HTTP live streaming coming soon.
    More native support in the works.
    Native support available via
    Khronos OpenMax IL

    View full-size slide

  26. Cloud  to  Device  Push
     
    Big deal for many pull-based apps. Will make devices use less battery.

    View full-size slide

  27. C2DM  –  The  Big  Picture
     

    View full-size slide

  28. Device  Administra  
    New in FroYo: Android Device Admin API.
    Administrator can set:
    Enable passwords
    Set password quality
    Max failed logins
    Prompt for new password
    Remotely wipe device data
    Lock the device
    App requests Device Admin permissions. If
    granted, admin policies apply. If not, app
    doesn’t work.
    Policies could be hard-coded or dynamic.
    Third-party enterprise solutions use this
    framework to build DM policies.

    View full-size slide

  29. File  System
     
    The file system has three main mount points. One
    for system, one for the apps, and one for whatever.
    Each app has its own sandbox easily accessible to
    it. No one else can access its data. The sandbox is
    in /data/data/com.marakana.yamba/
    SDCard is expected to always be there. It’s a good
    place for large files, such as movies and music.
    Everyone can access it.
    System partition is where the entire Android
    operating system is, customized by OEM or not.

    View full-size slide

  30. HELLO  WORLD!  

    View full-size slide

  31. Android  SDK  -­‐  What’s  In  The  Box
     
    SDK
    Tools
    Docs
    Platforms
    Data
    Skins
    Images
    Samples
    Add-ons
    Google

    View full-size slide

  32. Create  New  Project
     
    Use the Eclipse tool to create a new
    Android project.
    Here are some key constructs:
    Project   Eclipse  construct  
    Target   minimum  to  run  
    App  name   whatever  
    Package   Java  package  
    Ac

    View full-size slide

  33. Anatomy  
    of  An  App
     
    Java Code
    +
    XML and Other
    Resources
    +
    Manifest File
    =
    Android App

    View full-size slide

  34. Running  on  Emulator
     
    Emulator, not a simulator

    View full-size slide

  35. MAIN  BUILDING  BLOCKS  

    View full-size slide

  36. Yamba  Demo
     
    Let’s see a real-world medium
    complexity Android app in action:
    Yamba: Yet Another Micro Blogging App

    View full-size slide

  37. Ac  
    Android Application
    Main Activity
    Another
    Activity
    Another
    Activity
    An Activity
    represents a screen
    or a window. Sort of.

    View full-size slide

  38. Ac  
    Activities have a well-
    defined lifecycle. The
    Android OS manages
    your activity by
    changing its state.
    You fill in the blanks.

    View full-size slide

  39. Intents
     
    Intents represent
    events or actions.
    They are to
    Android apps what
    hyperlinks are to
    websites. Sort of.
    Intents can be
    implicit or explicit.

    View full-size slide

  40. Services
     
    Services are code that runs in the background. They
    can be started and stopped. Services doesn’t have
    UI.

    View full-size slide

  41. Service  Lifecycle
     
    Service also has a lifecycle, but it’s much simpler than
    activity’s.
    An activity typically starts and stops a service to do some
    work for it in the background, such as play music, check for
    new tweets, etc.
    Services can be bound or unbound.

    View full-size slide

  42. Remote  Services
     

    View full-size slide

  43. Content  Providers
     
    Content Providers share
    content with applications
    across application
    boundaries.
    Examples of built-in
    Content Providers are:
    Contacts, MediaStore,
    Settings and more.

    View full-size slide

  44. Content  Provider  Example
     

    View full-size slide

  45. Broadcast  Receivers
     
    An Intent-based publish-subscribe mechanism. Great for listening
    system events such as SMS messages.

    View full-size slide

  46. Architecture  of  An  App
     
    An Android application is a collection of many different
    building blocks. They are loosely coupled and can be
    reconfigured by the developer easily, or at least that’s
    the intention.
    Let’s look at 7 stages of Yamba next.

    View full-size slide

  47. Yamba  Part  1
     

    View full-size slide

  48. Yamba  Part  2
     

    View full-size slide

  49. Yamba  Part  3
     

    View full-size slide

  50. Yamba  Part  4
     

    View full-size slide

  51. Yamba  Part  5
     

    View full-size slide

  52. Yamba  Part  6
     

    View full-size slide

  53. Yamba  Part  7
     

    View full-size slide

  54. ANDROID  USER  INTERFACE  

    View full-size slide

  55. Two  UI  Approaches  
    Procedural   DeclaraKve  
    You  write  Java  code  
    Similar  to  Swing  or  AWT  
    You  write  XML  code  
    Similar  to  HTML  of  a  web  page  
    You can mix and match both styles. Best practice:
    •  Start with XML and declare most of UI
    •  Switch to Java and implement the UI logic

    View full-size slide

  56. XML-­‐Based  User  Interface
     
    Use WYSIWYG tools to build powerful XML-based UI.
    Easily customize it from Java. Separate concerns.

    View full-size slide

  57. Views  and  Layouts
     
    Layouts contain widgets and other
    layouts forming a “composite” pattern.

    View full-size slide

  58. Linear  Layout
     
    One of the most commonly
    used layouts. It lays its
    children next to each other,
    either horizontally or vertically.

    View full-size slide

  59. Rela  
    Children of relative layout are
    placed in relationship to each
    other. This layout is efficient.

    View full-size slide

  60. Table  Layout
     
    Table layout puts its children
    into table rows and columns.
    It is similar to an HTML table.

    View full-size slide

  61. Frame  Layout
     
    Frame layout places its
    children on top of each other,
    like a deck of cards. It is
    useful for widgets such as
    tabs or as a placeholder for
    views added
    programmatically.

    View full-size slide

  62. Common  UI  Components
     
    Android UI includes many
    common modern UI
    widgets, such as Buttons,
    Tabs, Progress Bars, Date
    and Time Pickers, etc.

    View full-size slide

  63. Selec  
    Some UI widgets may
    be linked to zillion
    pieces of data.
    Examples are ListView
    and Spinners
    (pull-downs).

    View full-size slide

  64. Adapters
     
    To make sure they run smoothly, Android uses
    Adapters to connect them to their data sources. A
    typical data source is an Array or a Database.
    Data
    Source
    Adapter

    View full-size slide

  65. Complex  Components
     
    Certain high-level components are simply
    available just like Views. Adding a Map or a
    Video to your application is almost like adding a
    Button or a piece of text.

    View full-size slide

  66. Menus  and  Dialogs
     

    View full-size slide

  67. Graphics  &  Anima  
    Android has rich support for 2D graphics.
    You can draw & animate from XML.
    You can use OpenGL for 3D graphics.

    View full-size slide

  68. Mul  
    AudioPlayer lets you simply specify
    the audio resource and play it.
    VideoView is a View that you can
    drop anywhere in your activity, point
    to a video file and play it.
    XML:
    android:id="@+id/video"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center” />
    Java:
    player = (VideoView) findViewById(R.id.video);
    player.setVideoPath("/sdcard/samplevideo.3gp");
    player.start();

    View full-size slide

  69. DEBUGGING    
    ANDROID  APPS  

    View full-size slide

  70. LogCat
     
    The universal, most
    versatile way to track
    what is going on in
    your app.
    Can be viewed via
    command line or
    Eclipse.
    Logs can be
    generated both from
    SDK Java code, or
    low-level C code via
    Bionic libc extension.

    View full-size slide

  71. Debugger
     
    Your standard debugger is included in SDK, with all the usual bells & whistles.

    View full-size slide

  72. TraceView
     
    TraceView helps you profile you application and find bottlenecks. It shows
    execution of various calls through the entire stack. You can zoom into specific
    calls.

    View full-size slide

  73. Hierarchy  Viewer
     
    Hierarchy Viewer helps
    you analyze your User
    Interface.
    Base UI tends to be the
    most “expensive” part of
    your application, this tool
    is very useful.

    View full-size slide

  74. ANDROID  
    SECURITY  

    View full-size slide

  75. Security  Overview
     
    No app can adversely impact other apps, user, or OS
    Cannot read/write user’s private data
    Cannot read other app’s data
    Cannot perform network access
    Cannot keep device awake, and so on
    Each application is its own sandbox
    To share resources, apps need to request permissions
    User must grant permissions at install time
    Linux manages security
    Not up to Dalvik (Java) but outsourced to Linux
    Native code (NDK) also adheres to sandboxing

    View full-size slide

  76. Applica  
    An application is an island on its own.
    It contains any number of Activities,
    Services, Receivers and Providers.
    It has its own file system, database,
    place to store native libraries.
    No other app can access any of its data
    without prior permission.

    View full-size slide

  77. Permissions
     
    A component that does
    something potentially
    dangerous can require
    callers to have permission to
    access it.
    App that wants to use it must
    have user grant it
    permission.
    Permissions are granted at
    install time. All or nothing.
    Forever.

    View full-size slide

  78. Some  System  Permissions
     
    ACCESS_COARSE_LOCATION   ACCESS_FINE_LOCATION  
    ACCESS_NETWORK_STATE   ACCESS_WIFI_STATE  
    BATTERY_STATS   BLUETOOTH  
    CALL_PHONE   CALL_PRIVILEGED  
    CAMERA   DEVICE_POWER  
    GET_ACCOUNTS   GET_TASKS  
    INSTALL_PACKAGES   INTERNET  
    KILL_BACKGROUND_PROCESSES   NFC  
    READ_CALENDAR   READ_CONTACTS  
    RECEIVE_SMS   RECORD_AUDIO  
    WRITE_EXTERNAL_STORAGE   WRITE_SETTINGS  

    View full-size slide

  79. Summary  
    Android is open and complete system for
    mobile development. It is based on Java
    and augmented with XML.
    It takes about 3-5 days of intensive
    training to learn Android application
    development for someone who has basic
    Java (or similar) experience.
    Marko Gargenta, Marakana.com
    [email protected]
    +1-415-647-7000

    View full-size slide