Share
Embed
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
Transcript
81 slides
-
Climbing Mount Android 1 Dr. Rajesh Vasa, 2011 Twitter: @rvasa
http://www.rvasa.com -
R. Vasa, 2011 Mobile Eco-System 2 Ad Networks Platform Content
Providers (Music/Video/Books) Handset OEMs Telephone Networks App. Distribution Cloud Infrastructure Billing -
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 -
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 -
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 -
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 -
R. Vasa, 2011 Android Device User Interaction 7 Menu Home
Back Android devices have three key buttons -
R. Vasa, 2011 There are variations in physical form 9
But all phones have Home, Menu, & Back Buttons -
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 -
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 -
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) -
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) -
R. Vasa, 2011 Tablet Menu Icon Visibility is contextual 14
Menu Sadly, menu position is not mandated (yuk?) -
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 -
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 -
R. Vasa, 2011 Android is a bi-lingual platform 18 Image
Source: http://www.tbray.org Java C/C++ -
R. Vasa, 2011 Most Android Code is in Java (but...)
19 Android Java is not 100% Sun Java ≠ -
R. Vasa, 2011 Android Java is different 20 No RMI
No Bytecode No AWT / Swing UI Different 2D/3D libs Different Class Load Mechanism -
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 -
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 -
R. Vasa, 2011 Android Emulator 25 Permits checking Portrait and
Landscape views -
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 -
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 -
R. Vasa, 2011 If your Java is rusty 28 Free
e-Book: http://www.mindview.net/Books/TIJ/ -
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 -
R. Vasa, 2011 The Android Way 30 Convention Configuration Development
is organised around a few conventions -
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 -
R. Vasa, 2011 Needs Resources @Multiple Resolutions 32 High Low
Medium Convention -
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 -
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 -
R. Vasa, 2011 Each Screen is an Activity •Android app.
is made up of Activities 36 Activity -
R. Vasa, 2011 Views are Android’s Key UI Building Block
•We need two views on the Activity 37 TextView ImageView -
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 -
R. Vasa, 2011 Android App. - Building Blocks 39 Activity
Layout Views (View Group) -
R. Vasa, 2011 Separation of Concerns in Android 40 Presentation
Functionality Layout Definition (main.xml) Activity Class Event Handling, I/O ... -
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 -
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 -
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 -
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 -
R. Vasa, 2011 Resources are given a unique ID 46
A unique reference id to resources is generated by the Android SDK tools Convention -
R. Vasa, 2011 Resources and Generated IDs 47 Generated Code
static final int australia=0x7f020000; -
R. Vasa, 2011 A Reference to Layout also Generated 48
All References are Integers -
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) -
R. Vasa, 2011 Layout is Referred to from Java Code
50 Activity View Group (Layout) Activity Class (Java) Layout Definition (main.xml) -
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 -
R. Vasa, 2011 Activity Creation 52 Method called (by Application
Launcher) when App is first launched -
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) -
R. Vasa, 2011 What is the “root” Activity? •How does
Android know which Activity to create first? 54 Answer: Application Manifest File -
R. Vasa, 2011 Application Manifest File 55 Activity Name Application
Icon Reference Category -
R. Vasa, 2011 Application Manifest File 56 Category indicates that
it can be launched -
R. Vasa, 2011 Application Manifest File 57 Main action indicates
that it is the starting point -
R. Vasa, 2011 Layouts and String Information •How did we
set the text to “Australia” 58 String constant -
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 -
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 -
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 -
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 -
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 -
R. Vasa, 2011 Building an App with Simple Interaction •Temperature
Conversion (C -> F) 64 -
R. Vasa, 2011 Views 65 TextView EditText Button TextView 4
Views (UI components) using a Linear Layout -
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 -
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 -
R. Vasa, 2011 UI Interaction Handling Pattern 69 The View
identifiers are defined in XML -
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 -
R. Vasa, 2011 Wiring up Multiple Activities 71 Select Back
Contact List Activity Contact Details -
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 -
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 -
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! -
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 -
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 -
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 -
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 -
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 -
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