SlideShare a Scribd company logo
HIT3328 / HIT8328 Software Development for
Mobile Devices
Dr. Rajesh Vasa, 2011
Twitter: @rvasa
Blog: http://rvasa.blogspot.com
1
Lecture 04
Complex
Interactions
R. Vasa, 20112
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (using Global Variables)
•Application Manifest File
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 20113
Android Device User
Interaction
Menu
HomeBack
R. Vasa, 20114
Android App. is made of
Activities
Activity
View Group
Views
(Layout)
R. Vasa, 20115
User Interface (generally) Built
in XMLActivity
View Group
(Layout)
Activity Class (Java)
Layout Definition
(main.xml)
PresentatioPresentatio
nn
FunctionaliFunctionali
tyty
R. Vasa, 20116
The Android Way - Convention not
Config.
•Source code (src)
•Generated code (gen)
•Resources (res)
•Images (@drawable)
•Layout of app (layout)
•Constants/Strings (@strings)
Conventions to Follow
R. Vasa, 20117
Portrait and Landscape Layouts
Conventions to Follow
R. Vasa, 20118
Provide Resources @Multiple
Resolutions
High
Low
Medium
Conventions to Follow
R. Vasa, 20119
View Identifiers
@+id TAG creates new identifiers
Conventions to Follow
R. Vasa, 201110
UI Interaction Handling Pattern
•Component.setOn......Listener ( handler
)
•E.g. button.setOnClickListener
•Handler is an anonymous inner class
•On...Listener handler = new
On....Listener() {}
R. Vasa, 201111
Android Activity Life Cycle
onCreate is called
when Activity Starts
Activity is
re-started
when
orientatio
n
changes
R. Vasa, 201112
We Retrieve State On Creation
State retrieval
done here
onSaveInstanceState(
) is called from this
state
(Save Saved here)
R. Vasa, 201113
Bundle stores simple state
information
BundleBundle
putString(key, value)
putDouble(key, value)
putInt(key, value)
putStringArray(k
ey, value[])
It is a Key, Value store system
(like a Hash Table or a Hash Map)
Code Snippet:
state.putString("inputTemperature", inputTemp);
Code Snippet:
state.putString("inputTemperature", inputTemp);
R. Vasa, 201114
Working with Resources
off.png
Layout XML File
Via Java Code
on.png
R. Vasa, 201115
Short Problem 1 - Passing Data
•Context: In Android -- Apps are made of
Activities. So, each Screen is a “new”
Activity
• We want to pass data between Activities.
• But, Activity construction is managed by the
Dalvik runtime. That is, cannot pass data into
constructor.
•What would you prefer to do?
• Store shared data in global variables available to
ALL Activities.
• Move all data to a separate data layer.
• Send primitive data bundles between
R. Vasa, 201116
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (using Global Variables)
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 201117
Wiring up Activities -- Typical
Use Case
Select
Back
Contact List Activity Contact Details
R. Vasa, 201118
Wiring up Activities -- Typical
Use Case
Select
Contact List Activity Contact Details
We re-use this
activity with
different data
Select
R. Vasa, 201119
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing options
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (using Global Variables)
•Passing Data Demo (using Intents)
R. Vasa, 201120
Data Passing Option - Global
Variables
•We can use Global Variables ... but,
•Widely accepted as a “risky” choice
•A few global variables are used in many
large systems (e.g. Linux Kernel Source
Code)
•Risk manageable in ‘small’ programs
•Good thread @ StackOverflow
http://goo.gl/EouH3
•Constant values as globals is ok (e.g.
R.java)
•Key Issue (to manage): How many objects
R. Vasa, 201121
Data Passing Option - Data
Layer
•We can store all data in a DBMS and access
it via a “data layer”
•Good idea when dealing with large /
complex blocks of data
•Overkill if we only need to store a few values
•The data store can be “in-memory”,
“on-disk”, and/or “on remote server”
R. Vasa, 201122
Data Passing Option - Bundles
•We can put data into a bundle and pass
this across using a “messaging
framework”
•Simple (once you understand the messaging
framework architecture)
•Persistence is not managed (like DBMS)
R. Vasa, 201123
Data Passing Option - iOS
Only!!
•You can pass data directly to methods in
another screen (UIViewController)
•UIViewController is approx. similar to Activity
•This option is not possible in Android -- this
was a “design intent” (design side-effect?)
R. Vasa, 201124
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (using Global Variables)
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 201125
iOS Apps. are directly managed
by O/S
UIAppDelegateUIAppDelegate
UIViewController-UIViewController-
AA
UIViewController-UIViewController-
BB
UIViewController-UIViewController-
CC
UIAppDelegate has Life
CycleView Controllers are
managed by the App
internally
Image Source: Apple Inc.
Life Cycle => Managed by Operating
System
R. Vasa, 201126
Android Activities are Managed by
O/S
Activity-AActivity-A
Activity-CActivity-C
Activity-BActivity-B
ApplicatiApplicati
onon Activities have
a parent
application
Activity has Life CycleApplication is NOT
managed directly by
the O/SLife Cycle => Managed by Operating
System
R. Vasa, 201127
A Key Design Different (iOS Vs
Android)
Activity-AActivity-A
Activity-CActivity-C
Activity-BActivity-B
UIAppDelegateUIAppDelegate
UIViewController-UIViewController-
AA
UIViewController-UIViewController-
BB
UIViewController-UIViewController-
CC
ApplicatiApplicati
onon
UIAppDelegate has Life
Cycle
Activities have
a parent
application
Activity has Life CycleApplication is NOT
managed directly by
the O/SLife Cycle => Managed by Operating
System
View Controllers are
managed by the App
internally
R. Vasa, 201128
Activity Life Cycle Design
Choice....
•Android developers decided to give Activity
a life cycle (rather than the application)
•This makes each Activity similar to a
separate program
•Hence, data passing is restricted to:
•Global Variables (stored in Application
object)
•Data bundles passed via async. messages
•Data stored externally in files or DBMS
R. Vasa, 201129
Short Problem 2 - Activity Design
Choice
•Unlike iOS ViewControllers, Activities have
been modelled to be (almost) like
independent programs
•What is the likely rationale for such a
choice?
•What would be the benefits?
R. Vasa, 201130
Only One Activity is
Active/Running
•Only one Activity can
be in the ‘foreground’
•When Activity-A calls
Activity-B
•Activity-B will be visible
to the user
(foreground)
•Activity-A is paused
(background)
R. Vasa, 201131
Activities are Stacked in
Android
•All created activities are placed on a Stack
•Activities ‘popped’ when ‘Back Button’ is
pressed
Activity-AActivity-A
Foreground/Acti
ve
If only one activity
is on the Activity
Stack then “back”
button exits it
R. Vasa, 201132
Activities are Stacked in
Android
•All current activities are placed on a Stack
•Newly started activities come into
foreground
Activity-AActivity-A
Activity-BActivity-B
Foreground/Acti
ve
starts
Background/
Paused
Back button will
pop top most
activity from
stack
R. Vasa, 201133
Activities are Stacked in
Android
•As additional activities are started, older
activities go into background
•All activities are placed on Activity Stack
Activity-AActivity-A
Activity-BActivity-B
Activity-CActivity-CForeground/Acti
ve
starts
starts
Background/Pause
d
R. Vasa, 201134
Short Problem 3 - Activity
Stacking
•Consider the following situation,
Activity-AActivity-A
Activity-BActivity-B
Activity-CActivity-C
starts
starts
Activity-AActivity-A
starts
Are these activities
the same object?
Ponder the interaction design
implications .....
Will Back Button Exit the
App?
R. Vasa, 201135
Lets get our feet wet
R. Vasa, 201136
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (using Global Variables)
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 201137
Demo 1 - Life Cycle of an Android
App.
•Walk-through of code provided along with
lecture handout.
•We can see the states by adding a little bit
of logging code to a few call-backs
R. Vasa, 201138
Life-Cycle Demo
onCreate, onStart,
onResume etc. are from the
Activity class
R. Vasa, 201139
Life-Cycle Demo (Watching
State)
R. Vasa, 201140
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (Global Variables)
•Application Manifest File
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 201141
Demo 2 - Passing Data
R. Vasa, 201142
Before data passing -- a quick
recap
•This app. makes use of nested layouts
•We can also make it look a bit nicer using
weights
R. Vasa, 201143
Anatomy of the App. (Nested
Layout)
Linear Layout
TextView
ImageView
Linear Layout
Button (Fruit)
Button (Vegetable)
Button (Drink)
R. Vasa, 201144
A Weighty Problem
Spot the difference in layout
How achieved? android:layout_weight=”1”
for all buttons in the layout
R. Vasa, 201145
Layout Weights are Handy
If all buttons are given the
same weight, then they will
be of same size
R. Vasa, 201146
Demo 2 - Passing Data
Activity - FoodMain Activity - FoodView
Data Passed:
Name (“Fruit”)
Image (fruit.png)
R. Vasa, 201147
Passing Data with Globals
•All Activities have a parent Application
object
•We can store data in this Application object
Activity-AActivity-A
Activity-CActivity-C
Activity-BActivity-B
ApplicatiApplicati
onon Activities have
a parent
application
We need to
extend the
Application class
to do this
R. Vasa, 201148
What Creates/Manages
Application?
•Application is created and managed by the
Android runtime
•There is one Application object created by
default
•We can extend the “Application Class” and
make our own
•But, we need to tell the Runtime about this
Application object via the Manifest XML
file
R. Vasa, 201149
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (Global Variables)
•Application Manifest File
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 201150
Manifest contains Application
Metadata
• Android runtime creates the Application object
• Application metadata is provided in the Manifest
XML
Manifest XML file is
part of the project
Auto-generated by Eclipse IDE
R. Vasa, 201151
Manifest XML - What is it?
Manifest informs Runtime about the App.Manifest informs Runtime about the App.
R. Vasa, 201152
Manifest XML - Contents
Application Name
R. Vasa, 201153
Manifest XML - Contains
Activity Names
Activity Name(s)
R. Vasa, 201154
Manifest XML - Refers to Icons
Launcher Icon
R. Vasa, 201155
Manifest XML - Refers to the
App. Name
Application
Label
R. Vasa, 201156
Passing Data with Globals
•All Activities have a parent Application
object
•We can store data in this Application object
FoodApplicatiFoodApplicati
onon
ApplicatiApplicati
onon
We need to
extend the
Application class
to do this
extends
R. Vasa, 201157
Global Vars. can be in the
Application
FoodApplicatiFoodApplicati
onon
ApplicatiApplicati
onon
extends
R. Vasa, 201158
Activities and Globals in
Application
•Activities can access data from the
Application object
We can also get to these variables from any Activi
(declared in the Manifest XML file)
We can also get to these variables from any Activit
(declared in the Manifest XML file)
R. Vasa, 201159
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (Global Variables)
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 201160
Demo 2 - Passing Data using
Intents
Activity - FoodMain Activity - FoodView
Data Passed:
Name (“Fruit”)
Image (fruit.png)
R. Vasa, 201161
Wiring up the Buttons (Another
Way)
Buttons
support onClick
in the layout
XML
Buttons
support onClick
in the layout
XML
R. Vasa, 201162
Storing Data in a Bundle
R. Vasa, 201163
Sending an Async. Message
Android uses an asynchronous messaging
model (known as Intents) to send messages
between Activities
Android uses an asynchronous messaging
model (known as Intents) to send messages
between Activities
R. Vasa, 201164
Sending an Async. Message
Setup Message and Store
Data in the Message
Setup Message and Store
Data in the Message
R. Vasa, 201165
Sending an Async. Message
Class that is sending
the Intent (message)
Class that is sending
the Intent (message)
R. Vasa, 201166
Sending an Async. Message
Class that will receive
the Intent (message)
Class that will receive
the Intent (message)
Class that is sending
the Intent (message)
Class that is sending
the Intent (message)
R. Vasa, 201167
Sending an Async. Message
Send the Message to the Activity
(Transmit)
Send the Message to the Activity
(Transmit)
R. Vasa, 201168
Message Receiving
Retrieve data from the
message
Retrieve data from the
message
R. Vasa, 201169
Intent Messages are
Asynchronous
•The intent system is completely
asynchronous -- similar to e-mail
•That is,
•The receiver will get the message only if
they request to see intents via getIntent()
method
•All transmitted messages are placed on a
‘Service Queue’
R. Vasa, 201170
Complex Domain Models
•Where do you hold a complex domain
model?(E.g. we have 4-5 classes in a
domain model)
•We can hold a reference to the domain
model objects in the Application
•This is fine if there are only a few objects
•Unlike Activity, Application is only terminated
if device runs low on memory
•If the data size is larger -- then best to use
the sqlite database
R. Vasa, 201171
Lecture Overview
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (Global Variables)
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 201172
Controlling Input Data Type
•A common task on forms is to restrict users
to certain data types
•Email Address
•Decimal Numbers
•Positive Integers
•Alpha Numeric
•On mobile devices -- development
platforms offer a simple way to control the
keyboard type
R. Vasa, 201173
Controlling Input Type
(Android)
•Android has a large number of options
•You can merge them to create more
complex input types
textUri
textEmailAddress
textPassword
textPersonName
number
numberSigned
numberDecimal
numberPassword
textUri
textEmailAddress
textPassword
textPersonName
number
numberSigned
numberDecimal
numberPassword
android:inputTypeandroid:inputType
R. Vasa, 201174
Input Type - Example
http://developer.android.com/reference/android/widget/TextView.html#attr_andro
id:inputType
More info. at the following URL
R. Vasa, 201175
Lecture Recap
•Recap (previous 2 weeks)
•Passing Data between Activities
•Data passing methods
•Activity Design Choice
•Activity Life Cycle
•Passing Data Demo (Global Variables)
•Passing Data Demo (using Intents)
•Controlling Input Type
R. Vasa, 201176
What’s next?
•Usability Principles - Mobile Form Design
•Using Dialogs
•Returning data back from an Activity
•Simple File I/O
•More complex layouts
•Exploring a few more widgets

More Related Content

PPTX
Http request and http response
PDF
WEB I - 01 - Introduction to Web Development
PPTX
Introduction to shodan
PPTX
Introduction to Network Security
PPTX
HTML Introduction, HTML History, HTML Uses, HTML benifits
PPTX
Creating Web Pages with Microsoft FrontPage - R.D.Sivakumar
PPTX
Web Development
PDF
Introduction to web programming with JavaScript
Http request and http response
WEB I - 01 - Introduction to Web Development
Introduction to shodan
Introduction to Network Security
HTML Introduction, HTML History, HTML Uses, HTML benifits
Creating Web Pages with Microsoft FrontPage - R.D.Sivakumar
Web Development
Introduction to web programming with JavaScript

What's hot (20)

PDF
Intro to HTML and CSS basics
PPTX
Cascading Style Sheet (CSS)
PPTX
Wireless network security
PPTX
Html & CSS
PPTX
Decomposition technique In Software Engineering
PPTX
laravel.pptx
PPTX
What is CSS?
PPT
Web Development using HTML & CSS
PPT
Advanced Cascading Style Sheets
PPTX
Application Architecture
PPTX
Web Development
PPTX
Css pseudo-classes
PDF
Introduction to SOFTWARE ARCHITECTURE
PPT
introduction to web technology
PPTX
(Fast) Introduction to HTML & CSS
PPT
Web Engineering
PPTX
Web servers
PPT
Introduction to JavaScript
Intro to HTML and CSS basics
Cascading Style Sheet (CSS)
Wireless network security
Html & CSS
Decomposition technique In Software Engineering
laravel.pptx
What is CSS?
Web Development using HTML & CSS
Advanced Cascading Style Sheets
Application Architecture
Web Development
Css pseudo-classes
Introduction to SOFTWARE ARCHITECTURE
introduction to web technology
(Fast) Introduction to HTML & CSS
Web Engineering
Web servers
Introduction to JavaScript
Ad

Viewers also liked (10)

PDF
HIT3328 - Chapter01 - Platforms and Devices
PDF
Presentazione progettoglobale
PDF
Ambiente manuale orto_sinergico_rilegato
ODP
Postmodernizm prezentacja
PDF
Manifesto ecovillaggiosubbiano
DOC
Per unmondonuovo
PDF
EduBrand Alumni Loyalty Program
PDF
HIT3328 - Chapter03 - Simple Interactive Apps
PPS
江南風雲錄與二泉映月
HIT3328 - Chapter01 - Platforms and Devices
Presentazione progettoglobale
Ambiente manuale orto_sinergico_rilegato
Postmodernizm prezentacja
Manifesto ecovillaggiosubbiano
Per unmondonuovo
EduBrand Alumni Loyalty Program
HIT3328 - Chapter03 - Simple Interactive Apps
江南風雲錄與二泉映月
Ad

Similar to HIT3328 - Chapter04 - Complex Interactions (20)

PDF
Android activities & views
PPTX
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
PPTX
Android Study Jams Session 4
PDF
Building robust apps
PPTX
App Fundamentals and Activity life cycle.pptx
PPTX
Pertemuan 03 - Activities and intents.pptx
PPTX
Android application development
PPTX
Android application componenets for android app development
PPTX
Android Mobile App Development basics PPT
PPTX
Basics 4
PPTX
Android beginners David
PPTX
Android app fundamentals
PDF
Android development - Activities, Views & Intents
PDF
2.1 Activities and Intents.pdf
PPTX
Technology and Android.pptx
PDF
Lecture 3 getting active through activities
DOCX
Android building blocks and application life cycle-chapter3
PPTX
DOCX
Android Application Components with Implementation & Examples
PDF
Android Basic Components
Android activities & views
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
Android Study Jams Session 4
Building robust apps
App Fundamentals and Activity life cycle.pptx
Pertemuan 03 - Activities and intents.pptx
Android application development
Android application componenets for android app development
Android Mobile App Development basics PPT
Basics 4
Android beginners David
Android app fundamentals
Android development - Activities, Views & Intents
2.1 Activities and Intents.pdf
Technology and Android.pptx
Lecture 3 getting active through activities
Android building blocks and application life cycle-chapter3
Android Application Components with Implementation & Examples
Android Basic Components

More from Yhal Htet Aung (18)

PDF
HIT3328 - Chapter0701 - Dialogs, Tabs and Lists
PDF
HIT3328 - Chapter0602 - Sketching Apps
PDF
HIT3328 - Chapter0601 - Menus and Lists
PDF
HIT3328 - Chapter0702 - Navigation Flow and Design Approach
PDF
HIT3328 - Chapter05 - Working with Forms
PDF
HIT3328 - Chapter02 - Foundation and Tools
PDF
CSC1100 - Chapter11 - Programming Languages and Program Development
PDF
CSC1100 - Chapter10 - Information System
PDF
CSC1100 - Chapter09 - Computer Security, Ethics and Privacy
PDF
CSC1100 - Chapter08 - Database Management
PDF
CSC1100 - Chapter07 - Communications & Networks
PDF
CSC1100 - Chapter06 - Operating System & Utility Programs
PDF
CSC1100 - Chapter05 - Storage
PDF
CSC1100 - Chapter04 - Output
PDF
CSC1100 - Chapter03 - Input
PDF
CSC1100 - Chapter02 - Components of the System Unit
PDF
CSC1100 - Chapter01 - Overview of Using Computers
PDF
CSC1100 - Chapter12 - Flow Charts
HIT3328 - Chapter0701 - Dialogs, Tabs and Lists
HIT3328 - Chapter0602 - Sketching Apps
HIT3328 - Chapter0601 - Menus and Lists
HIT3328 - Chapter0702 - Navigation Flow and Design Approach
HIT3328 - Chapter05 - Working with Forms
HIT3328 - Chapter02 - Foundation and Tools
CSC1100 - Chapter11 - Programming Languages and Program Development
CSC1100 - Chapter10 - Information System
CSC1100 - Chapter09 - Computer Security, Ethics and Privacy
CSC1100 - Chapter08 - Database Management
CSC1100 - Chapter07 - Communications & Networks
CSC1100 - Chapter06 - Operating System & Utility Programs
CSC1100 - Chapter05 - Storage
CSC1100 - Chapter04 - Output
CSC1100 - Chapter03 - Input
CSC1100 - Chapter02 - Components of the System Unit
CSC1100 - Chapter01 - Overview of Using Computers
CSC1100 - Chapter12 - Flow Charts

Recently uploaded (20)

PPTX
timber basics in structure mechanics (dos)
PDF
Govind singh Corporate office interior Portfolio
PPT
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
PPTX
UI UX Elective Course S1 Sistem Informasi RPS.pptx
PPTX
Media And Information Literacy for Grade 12
PPTX
Evolution_of_Computing_Presentation (1).pptx
PPTX
Presentation.pptx anemia in pregnancy in
PDF
2025_AIFG_Akane_Kikuchi_Empathy_Design.PDF
PPTX
22CDH01-V3-UNIT III-UX-UI for Immersive Design
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PDF
THEORY OF ID MODULE (Interior Design Subject)
PPTX
Project_Presentation Bitcoin Price Prediction
PPTX
Necrosgwjskdnbsjdmdndmkdndndnmdndndkdmdndkdkndmdmis.pptx
PPTX
Bitcoin predictor project presentation
PPTX
PROPOSAL tentang PLN di metode pelaksanaan.pptx
PDF
321 LIBRARY DESIGN.pdf43354445t6556t5656
PDF
intro_to_rust.pptx_123456789012446789.pdf
PPTX
Presentation1.pptxnmnmnmnjhjhkjkjkkjkjjk
PPT
robotS AND ROBOTICSOF HUMANS AND MACHINES
PPTX
a group casestudy on architectural aesthetic and beauty
timber basics in structure mechanics (dos)
Govind singh Corporate office interior Portfolio
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
UI UX Elective Course S1 Sistem Informasi RPS.pptx
Media And Information Literacy for Grade 12
Evolution_of_Computing_Presentation (1).pptx
Presentation.pptx anemia in pregnancy in
2025_AIFG_Akane_Kikuchi_Empathy_Design.PDF
22CDH01-V3-UNIT III-UX-UI for Immersive Design
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
THEORY OF ID MODULE (Interior Design Subject)
Project_Presentation Bitcoin Price Prediction
Necrosgwjskdnbsjdmdndmkdndndnmdndndkdmdndkdkndmdmis.pptx
Bitcoin predictor project presentation
PROPOSAL tentang PLN di metode pelaksanaan.pptx
321 LIBRARY DESIGN.pdf43354445t6556t5656
intro_to_rust.pptx_123456789012446789.pdf
Presentation1.pptxnmnmnmnjhjhkjkjkkjkjjk
robotS AND ROBOTICSOF HUMANS AND MACHINES
a group casestudy on architectural aesthetic and beauty

HIT3328 - Chapter04 - Complex Interactions

  • 1. HIT3328 / HIT8328 Software Development for Mobile Devices Dr. Rajesh Vasa, 2011 Twitter: @rvasa Blog: http://rvasa.blogspot.com 1 Lecture 04 Complex Interactions
  • 2. R. Vasa, 20112 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (using Global Variables) •Application Manifest File •Passing Data Demo (using Intents) •Controlling Input Type
  • 3. R. Vasa, 20113 Android Device User Interaction Menu HomeBack
  • 4. R. Vasa, 20114 Android App. is made of Activities Activity View Group Views (Layout)
  • 5. R. Vasa, 20115 User Interface (generally) Built in XMLActivity View Group (Layout) Activity Class (Java) Layout Definition (main.xml) PresentatioPresentatio nn FunctionaliFunctionali tyty
  • 6. R. Vasa, 20116 The Android Way - Convention not Config. •Source code (src) •Generated code (gen) •Resources (res) •Images (@drawable) •Layout of app (layout) •Constants/Strings (@strings) Conventions to Follow
  • 7. R. Vasa, 20117 Portrait and Landscape Layouts Conventions to Follow
  • 8. R. Vasa, 20118 Provide Resources @Multiple Resolutions High Low Medium Conventions to Follow
  • 9. R. Vasa, 20119 View Identifiers @+id TAG creates new identifiers Conventions to Follow
  • 10. R. Vasa, 201110 UI Interaction Handling Pattern •Component.setOn......Listener ( handler ) •E.g. button.setOnClickListener •Handler is an anonymous inner class •On...Listener handler = new On....Listener() {}
  • 11. R. Vasa, 201111 Android Activity Life Cycle onCreate is called when Activity Starts Activity is re-started when orientatio n changes
  • 12. R. Vasa, 201112 We Retrieve State On Creation State retrieval done here onSaveInstanceState( ) is called from this state (Save Saved here)
  • 13. R. Vasa, 201113 Bundle stores simple state information BundleBundle putString(key, value) putDouble(key, value) putInt(key, value) putStringArray(k ey, value[]) It is a Key, Value store system (like a Hash Table or a Hash Map) Code Snippet: state.putString("inputTemperature", inputTemp); Code Snippet: state.putString("inputTemperature", inputTemp);
  • 14. R. Vasa, 201114 Working with Resources off.png Layout XML File Via Java Code on.png
  • 15. R. Vasa, 201115 Short Problem 1 - Passing Data •Context: In Android -- Apps are made of Activities. So, each Screen is a “new” Activity • We want to pass data between Activities. • But, Activity construction is managed by the Dalvik runtime. That is, cannot pass data into constructor. •What would you prefer to do? • Store shared data in global variables available to ALL Activities. • Move all data to a separate data layer. • Send primitive data bundles between
  • 16. R. Vasa, 201116 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (using Global Variables) •Passing Data Demo (using Intents) •Controlling Input Type
  • 17. R. Vasa, 201117 Wiring up Activities -- Typical Use Case Select Back Contact List Activity Contact Details
  • 18. R. Vasa, 201118 Wiring up Activities -- Typical Use Case Select Contact List Activity Contact Details We re-use this activity with different data Select
  • 19. R. Vasa, 201119 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing options •Activity Design Choice •Activity Life Cycle •Passing Data Demo (using Global Variables) •Passing Data Demo (using Intents)
  • 20. R. Vasa, 201120 Data Passing Option - Global Variables •We can use Global Variables ... but, •Widely accepted as a “risky” choice •A few global variables are used in many large systems (e.g. Linux Kernel Source Code) •Risk manageable in ‘small’ programs •Good thread @ StackOverflow http://goo.gl/EouH3 •Constant values as globals is ok (e.g. R.java) •Key Issue (to manage): How many objects
  • 21. R. Vasa, 201121 Data Passing Option - Data Layer •We can store all data in a DBMS and access it via a “data layer” •Good idea when dealing with large / complex blocks of data •Overkill if we only need to store a few values •The data store can be “in-memory”, “on-disk”, and/or “on remote server”
  • 22. R. Vasa, 201122 Data Passing Option - Bundles •We can put data into a bundle and pass this across using a “messaging framework” •Simple (once you understand the messaging framework architecture) •Persistence is not managed (like DBMS)
  • 23. R. Vasa, 201123 Data Passing Option - iOS Only!! •You can pass data directly to methods in another screen (UIViewController) •UIViewController is approx. similar to Activity •This option is not possible in Android -- this was a “design intent” (design side-effect?)
  • 24. R. Vasa, 201124 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (using Global Variables) •Passing Data Demo (using Intents) •Controlling Input Type
  • 25. R. Vasa, 201125 iOS Apps. are directly managed by O/S UIAppDelegateUIAppDelegate UIViewController-UIViewController- AA UIViewController-UIViewController- BB UIViewController-UIViewController- CC UIAppDelegate has Life CycleView Controllers are managed by the App internally Image Source: Apple Inc. Life Cycle => Managed by Operating System
  • 26. R. Vasa, 201126 Android Activities are Managed by O/S Activity-AActivity-A Activity-CActivity-C Activity-BActivity-B ApplicatiApplicati onon Activities have a parent application Activity has Life CycleApplication is NOT managed directly by the O/SLife Cycle => Managed by Operating System
  • 27. R. Vasa, 201127 A Key Design Different (iOS Vs Android) Activity-AActivity-A Activity-CActivity-C Activity-BActivity-B UIAppDelegateUIAppDelegate UIViewController-UIViewController- AA UIViewController-UIViewController- BB UIViewController-UIViewController- CC ApplicatiApplicati onon UIAppDelegate has Life Cycle Activities have a parent application Activity has Life CycleApplication is NOT managed directly by the O/SLife Cycle => Managed by Operating System View Controllers are managed by the App internally
  • 28. R. Vasa, 201128 Activity Life Cycle Design Choice.... •Android developers decided to give Activity a life cycle (rather than the application) •This makes each Activity similar to a separate program •Hence, data passing is restricted to: •Global Variables (stored in Application object) •Data bundles passed via async. messages •Data stored externally in files or DBMS
  • 29. R. Vasa, 201129 Short Problem 2 - Activity Design Choice •Unlike iOS ViewControllers, Activities have been modelled to be (almost) like independent programs •What is the likely rationale for such a choice? •What would be the benefits?
  • 30. R. Vasa, 201130 Only One Activity is Active/Running •Only one Activity can be in the ‘foreground’ •When Activity-A calls Activity-B •Activity-B will be visible to the user (foreground) •Activity-A is paused (background)
  • 31. R. Vasa, 201131 Activities are Stacked in Android •All created activities are placed on a Stack •Activities ‘popped’ when ‘Back Button’ is pressed Activity-AActivity-A Foreground/Acti ve If only one activity is on the Activity Stack then “back” button exits it
  • 32. R. Vasa, 201132 Activities are Stacked in Android •All current activities are placed on a Stack •Newly started activities come into foreground Activity-AActivity-A Activity-BActivity-B Foreground/Acti ve starts Background/ Paused Back button will pop top most activity from stack
  • 33. R. Vasa, 201133 Activities are Stacked in Android •As additional activities are started, older activities go into background •All activities are placed on Activity Stack Activity-AActivity-A Activity-BActivity-B Activity-CActivity-CForeground/Acti ve starts starts Background/Pause d
  • 34. R. Vasa, 201134 Short Problem 3 - Activity Stacking •Consider the following situation, Activity-AActivity-A Activity-BActivity-B Activity-CActivity-C starts starts Activity-AActivity-A starts Are these activities the same object? Ponder the interaction design implications ..... Will Back Button Exit the App?
  • 35. R. Vasa, 201135 Lets get our feet wet
  • 36. R. Vasa, 201136 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (using Global Variables) •Passing Data Demo (using Intents) •Controlling Input Type
  • 37. R. Vasa, 201137 Demo 1 - Life Cycle of an Android App. •Walk-through of code provided along with lecture handout. •We can see the states by adding a little bit of logging code to a few call-backs
  • 38. R. Vasa, 201138 Life-Cycle Demo onCreate, onStart, onResume etc. are from the Activity class
  • 39. R. Vasa, 201139 Life-Cycle Demo (Watching State)
  • 40. R. Vasa, 201140 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (Global Variables) •Application Manifest File •Passing Data Demo (using Intents) •Controlling Input Type
  • 41. R. Vasa, 201141 Demo 2 - Passing Data
  • 42. R. Vasa, 201142 Before data passing -- a quick recap •This app. makes use of nested layouts •We can also make it look a bit nicer using weights
  • 43. R. Vasa, 201143 Anatomy of the App. (Nested Layout) Linear Layout TextView ImageView Linear Layout Button (Fruit) Button (Vegetable) Button (Drink)
  • 44. R. Vasa, 201144 A Weighty Problem Spot the difference in layout How achieved? android:layout_weight=”1” for all buttons in the layout
  • 45. R. Vasa, 201145 Layout Weights are Handy If all buttons are given the same weight, then they will be of same size
  • 46. R. Vasa, 201146 Demo 2 - Passing Data Activity - FoodMain Activity - FoodView Data Passed: Name (“Fruit”) Image (fruit.png)
  • 47. R. Vasa, 201147 Passing Data with Globals •All Activities have a parent Application object •We can store data in this Application object Activity-AActivity-A Activity-CActivity-C Activity-BActivity-B ApplicatiApplicati onon Activities have a parent application We need to extend the Application class to do this
  • 48. R. Vasa, 201148 What Creates/Manages Application? •Application is created and managed by the Android runtime •There is one Application object created by default •We can extend the “Application Class” and make our own •But, we need to tell the Runtime about this Application object via the Manifest XML file
  • 49. R. Vasa, 201149 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (Global Variables) •Application Manifest File •Passing Data Demo (using Intents) •Controlling Input Type
  • 50. R. Vasa, 201150 Manifest contains Application Metadata • Android runtime creates the Application object • Application metadata is provided in the Manifest XML Manifest XML file is part of the project Auto-generated by Eclipse IDE
  • 51. R. Vasa, 201151 Manifest XML - What is it? Manifest informs Runtime about the App.Manifest informs Runtime about the App.
  • 52. R. Vasa, 201152 Manifest XML - Contents Application Name
  • 53. R. Vasa, 201153 Manifest XML - Contains Activity Names Activity Name(s)
  • 54. R. Vasa, 201154 Manifest XML - Refers to Icons Launcher Icon
  • 55. R. Vasa, 201155 Manifest XML - Refers to the App. Name Application Label
  • 56. R. Vasa, 201156 Passing Data with Globals •All Activities have a parent Application object •We can store data in this Application object FoodApplicatiFoodApplicati onon ApplicatiApplicati onon We need to extend the Application class to do this extends
  • 57. R. Vasa, 201157 Global Vars. can be in the Application FoodApplicatiFoodApplicati onon ApplicatiApplicati onon extends
  • 58. R. Vasa, 201158 Activities and Globals in Application •Activities can access data from the Application object We can also get to these variables from any Activi (declared in the Manifest XML file) We can also get to these variables from any Activit (declared in the Manifest XML file)
  • 59. R. Vasa, 201159 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (Global Variables) •Passing Data Demo (using Intents) •Controlling Input Type
  • 60. R. Vasa, 201160 Demo 2 - Passing Data using Intents Activity - FoodMain Activity - FoodView Data Passed: Name (“Fruit”) Image (fruit.png)
  • 61. R. Vasa, 201161 Wiring up the Buttons (Another Way) Buttons support onClick in the layout XML Buttons support onClick in the layout XML
  • 62. R. Vasa, 201162 Storing Data in a Bundle
  • 63. R. Vasa, 201163 Sending an Async. Message Android uses an asynchronous messaging model (known as Intents) to send messages between Activities Android uses an asynchronous messaging model (known as Intents) to send messages between Activities
  • 64. R. Vasa, 201164 Sending an Async. Message Setup Message and Store Data in the Message Setup Message and Store Data in the Message
  • 65. R. Vasa, 201165 Sending an Async. Message Class that is sending the Intent (message) Class that is sending the Intent (message)
  • 66. R. Vasa, 201166 Sending an Async. Message Class that will receive the Intent (message) Class that will receive the Intent (message) Class that is sending the Intent (message) Class that is sending the Intent (message)
  • 67. R. Vasa, 201167 Sending an Async. Message Send the Message to the Activity (Transmit) Send the Message to the Activity (Transmit)
  • 68. R. Vasa, 201168 Message Receiving Retrieve data from the message Retrieve data from the message
  • 69. R. Vasa, 201169 Intent Messages are Asynchronous •The intent system is completely asynchronous -- similar to e-mail •That is, •The receiver will get the message only if they request to see intents via getIntent() method •All transmitted messages are placed on a ‘Service Queue’
  • 70. R. Vasa, 201170 Complex Domain Models •Where do you hold a complex domain model?(E.g. we have 4-5 classes in a domain model) •We can hold a reference to the domain model objects in the Application •This is fine if there are only a few objects •Unlike Activity, Application is only terminated if device runs low on memory •If the data size is larger -- then best to use the sqlite database
  • 71. R. Vasa, 201171 Lecture Overview •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (Global Variables) •Passing Data Demo (using Intents) •Controlling Input Type
  • 72. R. Vasa, 201172 Controlling Input Data Type •A common task on forms is to restrict users to certain data types •Email Address •Decimal Numbers •Positive Integers •Alpha Numeric •On mobile devices -- development platforms offer a simple way to control the keyboard type
  • 73. R. Vasa, 201173 Controlling Input Type (Android) •Android has a large number of options •You can merge them to create more complex input types textUri textEmailAddress textPassword textPersonName number numberSigned numberDecimal numberPassword textUri textEmailAddress textPassword textPersonName number numberSigned numberDecimal numberPassword android:inputTypeandroid:inputType
  • 74. R. Vasa, 201174 Input Type - Example http://developer.android.com/reference/android/widget/TextView.html#attr_andro id:inputType More info. at the following URL
  • 75. R. Vasa, 201175 Lecture Recap •Recap (previous 2 weeks) •Passing Data between Activities •Data passing methods •Activity Design Choice •Activity Life Cycle •Passing Data Demo (Global Variables) •Passing Data Demo (using Intents) •Controlling Input Type
  • 76. R. Vasa, 201176 What’s next? •Usability Principles - Mobile Form Design •Using Dialogs •Returning data back from an Activity •Simple File I/O •More complex layouts •Exploring a few more widgets