Climbing Mount Android (June 2011)
-
Upload
rajesh-vasa -
Category
Technology
-
view
105 -
download
1
description
Transcript of Climbing Mount Android (June 2011)
Climbing Mount Android
1
Rajesh Vasa, 2011
Twitter: @rvasahttp://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
HomeBack
Android devices have three key buttons
R. Vasa, 2011
Vendors can add additional buttons
8
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
BackPersonal 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)
• 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
17
Image Source: http://developer.android.com
Programming languages: Java, C/C++
R. Vasa, 2011
Android is a bi-lingual platform
18
Image Source: http://www.tbray.org
JavaC/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 (in many ways)
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
Eclipse IDE
23
R. Vasa, 2011
Eclipse IDE - Graphical UI Editor
24
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 to 3.0)
•Emulates the phone hardware (like VM Ware)
•Emulator does not have sensors (e.g. GPS, Gyro, Accelerometer, Cell phone etc.)
• It however offers ways to simulate these events
• So, I 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. 1.6 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
A Simple Android App.
34
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 and Layouts
•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
45
Resources in “res”
Convention
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
Linear Layout (View Group)
66
main.xml(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
73
Contact List Contact Detailsmessage
R. Vasa, 2011
Async. messaging called “Intents”
74
Contact List Contact Detailsintent
Activities communicate with each other via Intents
R. Vasa, 2011
Async. messaging called “Intents”
75
Activity-X Photo Viewerview 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
ApplicationActivities 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
R. Vasa, 2011
Security -- Android Devices
79
AndroidApplication
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, 201180
A Short Plug!!!
R. Vasa, 2011
Mobile Development @ Swinburne
•HIT8328 - Software Development for Mobile Devices
• Android focused
•HIT8329 - Creating Data Driven Mobile Applications
• iOS focused
• Portfolio Based Assessments
• We do not just cover API -- there is a strong conceptual foundation (prepare you to learn)
81
We Offer Options to Study Just One Subject
Teaching material will be available openly shortly
R. Vasa, 2011
Mobile Development @ Swinburne
•HIT8328 - Software Development for Mobile Devices
•HIT8329 - Creating Data Driven Mobile Applications
82
Teaching material will be available under an open license shortly
Follow @rvasa or @swinfict for update