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

Climbing Mount Android

Rajesh Vasa
September 26, 2011

Climbing Mount Android

What is Android? How does one start developing for this platform?
This talk will introduce Android, the key tools used for development, present core concepts, and design patterns used in Android development. The talk offers a great starting point for anyone curious about the Android platform.

Rajesh Vasa

September 26, 2011
Tweet

More Decks by Rajesh Vasa

Other Decks in Technology

Transcript

  1. R. Vasa, 2011 Mobile Eco-System 2 Ad Networks Platform Content

    Providers (Music/Video/Books) Handset OEMs Telephone Networks App. Distribution Cloud Infrastructure Billing
  2. R. Vasa, 2011 Android Eco-System 3 Ad Networks Platform Content

    Providers (Music/Video/Books) Handset (OEMs) Telephone Networks App. Distribution Cloud Infrastructure ** Google, Double Click Google, Amazon Android Google, Amazon Samsung, HTC, Motorola, Sony ... Billing Google Checkout
  3. R. Vasa, 2011 Focus of this talk... 4 Ad Networks

    Android Platform Content Providers (Music/Video/Books) Handset (OEMs) Telephone Networks App. Distribution Cloud Infrastructure ** Google, Double Click Google, Amazon Google, Amazon Samsung, HTC, Motorola, Sony ... Billing Google Checkout This talk will present a development perspective
  4. R. Vasa, 2011 Talk Overview •Devices •What is Android? •Development

    Tools •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Activities •Activity Life Cycle (the odd thing) 5
  5. R. Vasa, 2011 Roadmap - Where are we? •Devices •What

    is Android? •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Activities •Activity Life Cycle (the odd thing) 6
  6. R. Vasa, 2011 Android Device User Interaction 7 Menu Home

    Back Android devices have three key buttons
  7. R. Vasa, 2011 There are variations in physical form 9

    But all phones have Home, Menu, & Back Buttons
  8. R. Vasa, 2011 Home Button... •Typically, this will take you

    back to the Home Screen of the phone •Default behaviour ~ iPhone / iPad button 10 Home
  9. R. Vasa, 2011 Back Button •This will take you back

    to the previous screen •If app. has only one screen, this will exit app. 11 Back Personal Opinion: iPhone / iPad should borrow this button
  10. R. Vasa, 2011 Menu Button •Shows a contextual menu (if

    one is available) •Developers can write their own menus •Quite handy (but, causes Usability issues due to low discoverability) 12 Menu (as open)
  11. R. Vasa, 2011 Android for tablets is slightly different... 13

    Back, Home Where is the menu button? Action Bar (Buttons need not be physical in Android)
  12. R. Vasa, 2011 Tablet Menu Icon Visibility is contextual 14

    Menu Sadly, menu position is not mandated (yuk?)
  13. R. Vasa, 2011 Roadmap - Where are we? •Devices •What

    is Android? •Development Tools •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Activities •Activity Life Cycle (the odd thing) 15
  14. R. Vasa, 2011 What is Android? •Android is a platform

    •Operating System (with primitive API) •Frameworks (incl. components and libraries) 16 Applications Operating System (Customised Linux Kernel) Android Frameworks API
  15. R. Vasa, 2011 Android is a bi-lingual platform 18 Image

    Source: http://www.tbray.org Java C/C++
  16. R. Vasa, 2011 Most Android Code is in Java (but...)

    19 Android Java is not 100% Sun Java ≠
  17. R. Vasa, 2011 Android Java is different 20 No RMI

    No Bytecode No AWT / Swing UI Different 2D/3D libs Different Class Load Mechanism
  18. R. Vasa, 2011 Roadmap - Where are we? •Devices •What

    is Android? •Development Tools •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Activities •Activity Life Cycle (the odd thing) 21
  19. R. Vasa, 2011 Development Tools •Android SDK (Compiler and Emulator)

    •Eclipse IDE + Android Plug-in •Powerful debugger •Visual UI Builder •Ant (Build System) 22 Download from http://developer.android.com
  20. R. Vasa, 2011 Emulator is nice .. but phone is

    better •The emulator runs the Android O/S (you can run any version: 1.6 upwards -- incl. tablet) •Emulates the phone hardware (like VM Ware) •Emulator does not have sensors (e.g. GPS, Gyro, Accelerometer, Cell phone etc.) •It offers primitive methods to simulate some sensor events •Interesting factoid: You can send an SMS to the emulator or make a phone call to it 26
  21. R. Vasa, 2011 Emulators Vs Simulator •iOS offers a simulator

    •Android has gone down the emulator path •Trade-offs (pros and cons), •Simulators start-up faster, good enough •Emulators allow checking against rel. 2.1 of the O/S easily + closer to phone hardware •Emulators and Simulators cannot mimic real CPU speed, disk speed, network speed etc. (yet?) 27
  22. R. Vasa, 2011 If your Java is rusty 28 Free

    e-Book: http://www.mindview.net/Books/TIJ/
  23. R. Vasa, 2011 Roadmap - Where are we? •Devices •What

    is Android? •Development Tools •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Activities •Activity Life Cycle (the odd thing) 29
  24. R. Vasa, 2011 Android Project Structure (convention) •Source code (src)

    •Generated code (gen) •Resources (res) •Images (drawable) •Layout of app (layout) •Constants/Strings (values) 31
  25. R. Vasa, 2011 Roadmap - Where are we? •Devices •What

    is Android? •Development Tools •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Screens (Activities) •Activity Life Cycle (interesting design choice) 33
  26. R. Vasa, 2011 What is involved? •Place UI controls (Text

    and Image) •Layout the controls •Centre text •Make text large font •Display Image to take up all space 35
  27. R. Vasa, 2011 Each Screen is an Activity •Android app.

    is made up of Activities 36 Activity
  28. R. Vasa, 2011 Views are Android’s Key UI Building Block

    •We need two views on the Activity 37 TextView ImageView
  29. R. Vasa, 2011 Views are Placed inside a View Group

    •Different types of pre-defined layouts •Linear, Relative, Table, Frame etc.. 38 View Group a.k.a Layout
  30. R. Vasa, 2011 Separation of Concerns in Android 40 Presentation

    Functionality Layout Definition (main.xml) Activity Class Event Handling, I/O ...
  31. R. Vasa, 2011 UI (Layout) Definition •Layout definition is generally

    in an XML file •Hand coded or Visual Editor •Can be also be done in Java Code (yuk!) 41 Layout Definition XML File
  32. R. Vasa, 2011 Android Offers a number of UI Controls

    •Offers all standard controls and lot more... 42 Progress These are a small subset of available controls
  33. R. Vasa, 2011 View Groups (Layouts for us mortals) •Android

    offers the following View Groups, •Linear Layout (Horizontal or Vertical) •Absolute Layout (You set X, Y for each View) •Table Layout (Rows and Columns) •Relative Layout (Position relative to other Views) •Frame Layout (Show only one view at a time) •Scroll View (Permits scrolling of the screen) •View Groups can be nested 43
  34. R. Vasa, 2011 Generated Code, Layout & Resources •How did

    Australia image get into the App.? •How did we set the text to “Australia”? •Conventions •Layout Defined in /layout/main.xml •Resources Placed in /res/drawable-* •String values defined in /values/strings.xml 44
  35. R. Vasa, 2011 Resources are given a unique ID 46

    A unique reference id to resources is generated by the Android SDK tools Convention
  36. R. Vasa, 2011 Resources and Generated IDs 47 Generated Code

    static final int australia=0x7f020000;
  37. R. Vasa, 2011 Identifiers are used to access resources 49

    Reference to the layout This is the Activity Class (Android Runtime will Render this Layout)
  38. R. Vasa, 2011 Layout is Referred to from Java Code

    50 Activity View Group (Layout) Activity Class (Java) Layout Definition (main.xml)
  39. R. Vasa, 2011 Who writes the Activity code? 51 This

    block of code is created by IDE/SDK when we create new Android project You can also write you own
  40. R. Vasa, 2011 Activity Creation - Layout Rendering 53 Method

    call will pass the reference to the layout that needs to be rendered on the screen (“Rendering” is a two-pass process: measure and draw)
  41. R. Vasa, 2011 What is the “root” Activity? •How does

    Android know which Activity to create first? 54 Answer: Application Manifest File
  42. R. Vasa, 2011 Layouts and String Information •How did we

    set the text to “Australia” 58 String constant
  43. R. Vasa, 2011 Using Graphical Resources •How did the Australia

    image get into layout? 59 Layout can refer to resources @drawable is a special tag
  44. R. Vasa, 2011 What is it with the @ tag?

    •Constant Resources in Android can be referred using the “@” tag in XML layout •Example: @drawable, @string ... 60 @drawable/australia @drawable/bots
  45. R. Vasa, 2011 @ Tag and Multiple Screen Resolutions •Dealing

    with multiple screen resolutions @drawable/icon Android Runtime decides best resource to use based on hardware capabilities
  46. R. Vasa, 2011 Significance of hdpi/ldpi/mdpi 62 High-Res, 240 dpi

    screen Low-Res, 120 dpi screen Med-Res, 160 dpi screen Different resolution images
  47. R. Vasa, 2011 Roadmap - Where are we? •Devices •What

    is Android? •Development Tools •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Screens (Activities) •Life Cycle & interesting design choices 63
  48. R. Vasa, 2011 Views 65 TextView EditText Button TextView 4

    Views (UI components) using a Linear Layout
  49. R. Vasa, 2011 View Identifiers •We need a way to

    identify components that we created in the layout •E.g. To read input data from the field 67 @+id TAG creates new identifiers
  50. R. Vasa, 2011 UI Interaction Handling Pattern •Component.setOn......Listener ( handler

    ) •E.g. button.setOnClickListener •Handler is an anonymous inner class •On...Listener handler = new On....Listener() {} 68
  51. R. Vasa, 2011 Roadmap - Where are we? •Devices •What

    is Android? •Development Tools •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Screens (Activities) •Life Cycle & interesting design choices 70
  52. R. Vasa, 2011 Wiring up Multiple Activities 71 Select Back

    Contact List Activity Contact Details
  53. R. Vasa, 2011 Activities are Stacked in Android •All current

    activities are placed on a Stack •Newly started activities come into foreground 72 Contact List Contact Details Foreground/Active starts Background/ Paused Back button will pop top most activity from stack
  54. R. Vasa, 2011 Activities are like mini-processes •Android activities have

    their own life cycle •Communication between Activities is done by Asynchronous Messaging -- called “Intents” 73 Contact List Contact Details message
  55. R. Vasa, 2011 Async. messaging called “Intents” 74 Contact List

    Contact Details intent Activities communicate with each other via Intents Think of an Intent as a message -- like email!
  56. R. Vasa, 2011 Async. messaging called “Intents” 75 Activity-X Photo

    Viewer view photo intent You can send a general purpose message (intent), all applications capable of handling that Intent will respond Framework prescribes conventions for common intents
  57. R. Vasa, 2011 Roadmap - Where are we? •Devices •What

    is Android? •Development Tools •The Android Way •Anatomy of a Simple Android Application •An Interactive Android Application •Dealing with Multiple Screens (Activities) •Life Cycle (& interesting design choices) 76
  58. R. Vasa, 2011 Android Activities are Managed by O/S 77

    Activity-A Activity-C Activity-B Application Activities have a parent application Activity has Life Cycle Application is NOT managed directly by the O/S Life Cycle is Managed by Android Framework
  59. R. Vasa, 2011 Android Activity Life Cycle 78 Activity is

    re-started when orientation changes Developers have to save and retrieve state if orientation changes No, I am not kidding
  60. R. Vasa, 2011 Security -- Android Devices 79 Android Application

    User UID (User ID) has also has The UID is generated at install time based on the signature and package name File System Access Permissions determines
  61. R. Vasa, 2011 Mobile Development @ Swinburne •HIT8328 - Software

    Development for Mobile Devices (Lab work in Android platform) •HIT8329 - Creating Data Driven Mobile Applications (iOS focused) • Portfolio Based Assessment (no EXAM!) • We do not focus only on API -- there is a strong conceptual foundation (preparing you to learn) • Can study both subjects as single units 81 Follow @rvasa for updates Swinburne University of Technology is in Melbourne, Australia