First Steps with Android - An Exciting Introduction

64
First Steps with Android Cesar Augusto Nogueira @cesarnogcps www.brazilianswhocode.com

description

Get to know more about Android with this exciting introduction. Be free to share! #Android #Development #Java

Transcript of First Steps with Android - An Exciting Introduction

Page 1: First Steps with Android - An Exciting Introduction

First Steps with Android

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

The Big Picture

What is Android

Get you an idea of how to start developing Android

applications

Introduce major Android application concepts

Walk you through a sample application in the

development environments

Install the development environments

Create the first Android Application

Goals

NOT a super difficult course

Guide you to go through essentials (tons of resources are available)

NOT a Java language class

Learn how to use the Android SDK APIs

NOT an Android internal course

Learn Android Application Development

NOT a lecture oriented course

Learn by doing the hands-on programming

NOT an advanced course

Introduce from the very basics (tool installation)

What is Android

System architecture

Develop environment installation

Hello World

Application components

Tool chain

Agenda

Androidrsquos web page

httpdeveloperandroidcomsdkindexhtml

Android SDK (httpdeveloperandroidcom)

Windows Linux Mac

Utilizes the Java language

Different Libraries

Well-documented

httpdeveloperandroidcomreferencepackageshtml

Freely downloaded

Android

Android versions

Android 15 (Apr 2009) ndash Cupcake

First really stablerobust version

Android 16 (Sep 2009)ndash Donut

First lsquoupdatablersquo version

Android 20 (Oct 2009) Android 21 (Jan 2010)ndash Eacuteclair

Android 22 (May 2010) ndash Froyo

Android 23 (Q4 2010) ndash Gingerbread

Android 30 (Honeycomb)

Android 40 (Ice Cream Sandwich)

Android 42 (Jelly Bean)

Android 44 (Kitkat)

httpenwikipediaorgwikiAndroid_(operating system)

Versioning

Higher version addressed many issues

Better audiovideo

Better sensing

Use of GPS

Multi touch

Other

Android is a mobile operating system initially developed by Android Inc (bought by Google 2005)

Android is the software platform from Google and the Open Handset Alliance (OHA) that has the potential to revolutionize the global cell phone market

A free open source mobile platform

Android is not a device or a product

Androidtrade consists of a complete set of software components for mobile devices including

an operating system (Linux-based multiprocess multithreaded OS)

middleware and

key mobile applications

It has the capability to make inroads in many other (non‐phone) embedded application markets such as a tablet a DVR a handheld GPS an MP3 player etc

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 2: First Steps with Android - An Exciting Introduction

The Big Picture

What is Android

Get you an idea of how to start developing Android

applications

Introduce major Android application concepts

Walk you through a sample application in the

development environments

Install the development environments

Create the first Android Application

Goals

NOT a super difficult course

Guide you to go through essentials (tons of resources are available)

NOT a Java language class

Learn how to use the Android SDK APIs

NOT an Android internal course

Learn Android Application Development

NOT a lecture oriented course

Learn by doing the hands-on programming

NOT an advanced course

Introduce from the very basics (tool installation)

What is Android

System architecture

Develop environment installation

Hello World

Application components

Tool chain

Agenda

Androidrsquos web page

httpdeveloperandroidcomsdkindexhtml

Android SDK (httpdeveloperandroidcom)

Windows Linux Mac

Utilizes the Java language

Different Libraries

Well-documented

httpdeveloperandroidcomreferencepackageshtml

Freely downloaded

Android

Android versions

Android 15 (Apr 2009) ndash Cupcake

First really stablerobust version

Android 16 (Sep 2009)ndash Donut

First lsquoupdatablersquo version

Android 20 (Oct 2009) Android 21 (Jan 2010)ndash Eacuteclair

Android 22 (May 2010) ndash Froyo

Android 23 (Q4 2010) ndash Gingerbread

Android 30 (Honeycomb)

Android 40 (Ice Cream Sandwich)

Android 42 (Jelly Bean)

Android 44 (Kitkat)

httpenwikipediaorgwikiAndroid_(operating system)

Versioning

Higher version addressed many issues

Better audiovideo

Better sensing

Use of GPS

Multi touch

Other

Android is a mobile operating system initially developed by Android Inc (bought by Google 2005)

Android is the software platform from Google and the Open Handset Alliance (OHA) that has the potential to revolutionize the global cell phone market

A free open source mobile platform

Android is not a device or a product

Androidtrade consists of a complete set of software components for mobile devices including

an operating system (Linux-based multiprocess multithreaded OS)

middleware and

key mobile applications

It has the capability to make inroads in many other (non‐phone) embedded application markets such as a tablet a DVR a handheld GPS an MP3 player etc

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 3: First Steps with Android - An Exciting Introduction

NOT a super difficult course

Guide you to go through essentials (tons of resources are available)

NOT a Java language class

Learn how to use the Android SDK APIs

NOT an Android internal course

Learn Android Application Development

NOT a lecture oriented course

Learn by doing the hands-on programming

NOT an advanced course

Introduce from the very basics (tool installation)

What is Android

System architecture

Develop environment installation

Hello World

Application components

Tool chain

Agenda

Androidrsquos web page

httpdeveloperandroidcomsdkindexhtml

Android SDK (httpdeveloperandroidcom)

Windows Linux Mac

Utilizes the Java language

Different Libraries

Well-documented

httpdeveloperandroidcomreferencepackageshtml

Freely downloaded

Android

Android versions

Android 15 (Apr 2009) ndash Cupcake

First really stablerobust version

Android 16 (Sep 2009)ndash Donut

First lsquoupdatablersquo version

Android 20 (Oct 2009) Android 21 (Jan 2010)ndash Eacuteclair

Android 22 (May 2010) ndash Froyo

Android 23 (Q4 2010) ndash Gingerbread

Android 30 (Honeycomb)

Android 40 (Ice Cream Sandwich)

Android 42 (Jelly Bean)

Android 44 (Kitkat)

httpenwikipediaorgwikiAndroid_(operating system)

Versioning

Higher version addressed many issues

Better audiovideo

Better sensing

Use of GPS

Multi touch

Other

Android is a mobile operating system initially developed by Android Inc (bought by Google 2005)

Android is the software platform from Google and the Open Handset Alliance (OHA) that has the potential to revolutionize the global cell phone market

A free open source mobile platform

Android is not a device or a product

Androidtrade consists of a complete set of software components for mobile devices including

an operating system (Linux-based multiprocess multithreaded OS)

middleware and

key mobile applications

It has the capability to make inroads in many other (non‐phone) embedded application markets such as a tablet a DVR a handheld GPS an MP3 player etc

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 4: First Steps with Android - An Exciting Introduction

What is Android

System architecture

Develop environment installation

Hello World

Application components

Tool chain

Agenda

Androidrsquos web page

httpdeveloperandroidcomsdkindexhtml

Android SDK (httpdeveloperandroidcom)

Windows Linux Mac

Utilizes the Java language

Different Libraries

Well-documented

httpdeveloperandroidcomreferencepackageshtml

Freely downloaded

Android

Android versions

Android 15 (Apr 2009) ndash Cupcake

First really stablerobust version

Android 16 (Sep 2009)ndash Donut

First lsquoupdatablersquo version

Android 20 (Oct 2009) Android 21 (Jan 2010)ndash Eacuteclair

Android 22 (May 2010) ndash Froyo

Android 23 (Q4 2010) ndash Gingerbread

Android 30 (Honeycomb)

Android 40 (Ice Cream Sandwich)

Android 42 (Jelly Bean)

Android 44 (Kitkat)

httpenwikipediaorgwikiAndroid_(operating system)

Versioning

Higher version addressed many issues

Better audiovideo

Better sensing

Use of GPS

Multi touch

Other

Android is a mobile operating system initially developed by Android Inc (bought by Google 2005)

Android is the software platform from Google and the Open Handset Alliance (OHA) that has the potential to revolutionize the global cell phone market

A free open source mobile platform

Android is not a device or a product

Androidtrade consists of a complete set of software components for mobile devices including

an operating system (Linux-based multiprocess multithreaded OS)

middleware and

key mobile applications

It has the capability to make inroads in many other (non‐phone) embedded application markets such as a tablet a DVR a handheld GPS an MP3 player etc

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 5: First Steps with Android - An Exciting Introduction

Androidrsquos web page

httpdeveloperandroidcomsdkindexhtml

Android SDK (httpdeveloperandroidcom)

Windows Linux Mac

Utilizes the Java language

Different Libraries

Well-documented

httpdeveloperandroidcomreferencepackageshtml

Freely downloaded

Android

Android versions

Android 15 (Apr 2009) ndash Cupcake

First really stablerobust version

Android 16 (Sep 2009)ndash Donut

First lsquoupdatablersquo version

Android 20 (Oct 2009) Android 21 (Jan 2010)ndash Eacuteclair

Android 22 (May 2010) ndash Froyo

Android 23 (Q4 2010) ndash Gingerbread

Android 30 (Honeycomb)

Android 40 (Ice Cream Sandwich)

Android 42 (Jelly Bean)

Android 44 (Kitkat)

httpenwikipediaorgwikiAndroid_(operating system)

Versioning

Higher version addressed many issues

Better audiovideo

Better sensing

Use of GPS

Multi touch

Other

Android is a mobile operating system initially developed by Android Inc (bought by Google 2005)

Android is the software platform from Google and the Open Handset Alliance (OHA) that has the potential to revolutionize the global cell phone market

A free open source mobile platform

Android is not a device or a product

Androidtrade consists of a complete set of software components for mobile devices including

an operating system (Linux-based multiprocess multithreaded OS)

middleware and

key mobile applications

It has the capability to make inroads in many other (non‐phone) embedded application markets such as a tablet a DVR a handheld GPS an MP3 player etc

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 6: First Steps with Android - An Exciting Introduction

Android SDK (httpdeveloperandroidcom)

Windows Linux Mac

Utilizes the Java language

Different Libraries

Well-documented

httpdeveloperandroidcomreferencepackageshtml

Freely downloaded

Android

Android versions

Android 15 (Apr 2009) ndash Cupcake

First really stablerobust version

Android 16 (Sep 2009)ndash Donut

First lsquoupdatablersquo version

Android 20 (Oct 2009) Android 21 (Jan 2010)ndash Eacuteclair

Android 22 (May 2010) ndash Froyo

Android 23 (Q4 2010) ndash Gingerbread

Android 30 (Honeycomb)

Android 40 (Ice Cream Sandwich)

Android 42 (Jelly Bean)

Android 44 (Kitkat)

httpenwikipediaorgwikiAndroid_(operating system)

Versioning

Higher version addressed many issues

Better audiovideo

Better sensing

Use of GPS

Multi touch

Other

Android is a mobile operating system initially developed by Android Inc (bought by Google 2005)

Android is the software platform from Google and the Open Handset Alliance (OHA) that has the potential to revolutionize the global cell phone market

A free open source mobile platform

Android is not a device or a product

Androidtrade consists of a complete set of software components for mobile devices including

an operating system (Linux-based multiprocess multithreaded OS)

middleware and

key mobile applications

It has the capability to make inroads in many other (non‐phone) embedded application markets such as a tablet a DVR a handheld GPS an MP3 player etc

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 7: First Steps with Android - An Exciting Introduction

Android

Android versions

Android 15 (Apr 2009) ndash Cupcake

First really stablerobust version

Android 16 (Sep 2009)ndash Donut

First lsquoupdatablersquo version

Android 20 (Oct 2009) Android 21 (Jan 2010)ndash Eacuteclair

Android 22 (May 2010) ndash Froyo

Android 23 (Q4 2010) ndash Gingerbread

Android 30 (Honeycomb)

Android 40 (Ice Cream Sandwich)

Android 42 (Jelly Bean)

Android 44 (Kitkat)

httpenwikipediaorgwikiAndroid_(operating system)

Versioning

Higher version addressed many issues

Better audiovideo

Better sensing

Use of GPS

Multi touch

Other

Android is a mobile operating system initially developed by Android Inc (bought by Google 2005)

Android is the software platform from Google and the Open Handset Alliance (OHA) that has the potential to revolutionize the global cell phone market

A free open source mobile platform

Android is not a device or a product

Androidtrade consists of a complete set of software components for mobile devices including

an operating system (Linux-based multiprocess multithreaded OS)

middleware and

key mobile applications

It has the capability to make inroads in many other (non‐phone) embedded application markets such as a tablet a DVR a handheld GPS an MP3 player etc

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 8: First Steps with Android - An Exciting Introduction

Android is a mobile operating system initially developed by Android Inc (bought by Google 2005)

Android is the software platform from Google and the Open Handset Alliance (OHA) that has the potential to revolutionize the global cell phone market

A free open source mobile platform

Android is not a device or a product

Androidtrade consists of a complete set of software components for mobile devices including

an operating system (Linux-based multiprocess multithreaded OS)

middleware and

key mobile applications

It has the capability to make inroads in many other (non‐phone) embedded application markets such as a tablet a DVR a handheld GPS an MP3 player etc

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 9: First Steps with Android - An Exciting Introduction

Android Open Source Project web page to download the source

httpsourceandroidcomdownload

How many lines of code does it take to create the Android OS

httpwwwgubatroncomblog20100523how-many-

lines-of-code-does-it-take-to-create-the-android-os

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 10: First Steps with Android - An Exciting Introduction

Listen from the project creatorsdevelopers (219 min)

Nick Sears Co‐founder of Android

Steve Horowitz Engineering Director

You will hear statements such as

ldquohellipcurrently it is too difficult to make new products hellip open software brings more innovation hellip choices hellip lower costs hellip more applications such as family planner my taxes understand my wife better hellip rdquo

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 11: First Steps with Android - An Exciting Introduction

Quoting from wwwOpenHandsetAlliancecom page

ldquohellip Open Handset Alliancetrade a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer less expensive and better mobile experience

Together we have developed Androidtrade the first complete open and free mobile platform

We are committed to commercially deploy handsets and services using the Android Platform ldquo

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 12: First Steps with Android - An Exciting Introduction

Short video (4 min)

Showing Dave Bort and Dan

Borstein two members of

the Android Open Source

Project talk about the

project

See Android Developers

httpwwwyoutubecomwatchv=7Y4thikv-OM

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 13: First Steps with Android - An Exciting Introduction

Android is a software environment built for mobile devices

It is not a hardware platform

Android includes

Linux kernel‐based OS

a rich UI

telephone functionality

end‐user applications

code libraries

application frameworks

multimedia support

User applications are built for Android in Java

The Android PlatformAgain what did they say about Android

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 14: First Steps with Android - An Exciting Introduction

Android vs Competitors

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 15: First Steps with Android - An Exciting Introduction

Have all of the major components of computing platform but specially

designed for the mobile environment

(NOT a general purpose computing environment)

Application framework enabling reuse and replacement of components

Dalvik virtual machine optimized for mobile devices

Integrated browser based on the open source WebKit engine

Optimized graphics powered by a custom 2D graphics library 3D graphics

based on the OpenGL ES specification (hardware acceleration optional)

SQLite for structured data storage

Media support for common audio video and still image formats (MPEG4

H264 MP3 AAC AMR JPG PNG GIF)

GSM Telephony (hardware dependent)

Bluetooth EDGE 3G and WiFi (hardware dependent)

Camera GPS compass and accelerometer (hardware dependent)

Rich development environment including a device emulator tools for

debugging memory and performance profiling and a plugin for

the Eclipse IDE

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 16: First Steps with Android - An Exciting Introduction

Available at video 13

httpwwwyoutubecomwatchv=QBGfUs9mQYY

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 17: First Steps with Android - An Exciting Introduction

httpsitesgooglecomsiteioinside-the-android-application-framework

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 18: First Steps with Android - An Exciting Introduction

Linux kernel is a proven core platform

Reliability is more important than performance when it comes

to a mobile phone because voice communication is the

primary use of a phone

Linux can help meet this requirement

Linux provides a hardware abstraction layer letting the upper

levels remain unchanged despite changes in the underlying

hardware

As new accessories appear on the market drivers can be

written at the Linux level to provide support just as on other

Linux platforms

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 19: First Steps with Android - An Exciting Introduction

User applications as well as core Android applications are

written in the Java programming language and are compiled

into byte codes

Android byte codes are interpreted at runtime by an

interpreter known as the Dalvik virtual machine

Why another Virtual Machine

Android byte code files are logically equivalent to Java byte codes

but they permit Android to

run its applications in its own virtual environment that is free from

Sunrsquos licensing restrictions and

an open platform upon which Google and potentially the open source

community can improve as necessary

Being optimized for low memory requirements

The VM was slimmed down to use less space

The constant pool has been modified to use only 32-bit indexes to

simplify the interpreter

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 20: First Steps with Android - An Exciting Introduction

Good Video References

httpwwwyoutubecomwatchv=ptjedOZEXPM

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 21: First Steps with Android - An Exciting Introduction

There are four building blocks (components) to an Android

application

Activity represents a screen of the app Moving from one activity

to another is done using an Intent

An Intent describes what an application wants done in terms of the

action and the data to act upon eg PICK a contact

Intent Receiver (broadcast receiver) is used when you want code

in your application to execute in reaction to an external event

eg when the phone rings

Service is a faceless tasks that run in the background like a sync

session

Content Provider is a class that implements a standard set of

methods to let other applications store and retrieve the type of

data that is handled by that content provider

Application Anatomy

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 22: First Steps with Android - An Exciting Introduction

Android DevelopmentApplications are composed of

o Activities

Visual user interface for one focused endeavor

o Services

Runs in the background for an indefinite period of time

Intents

Asynchronous synchronous messaging URL dispatching on steroids Glues many Activities and Services together to make an application Provides interactivity between applications

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 23: First Steps with Android - An Exciting Introduction

Email Application - Example

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 24: First Steps with Android - An Exciting Introduction

Android application runs in its own Linux process

The process lifetime is handled by the system not by the app

when the system needs memory to run new applications one of

the background app is killed

Thats why it is important to use correctly Activities Services

and Intent Receivers

Not using them in the right way can result in the system killing

the applications process while it is doing important work

Example starting a thread to download a file from an Activity or an

IntentReceiver A Service should be used instead

Life Cycle of an

Android Application

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 25: First Steps with Android - An Exciting Introduction

Android determines which process to kill when low on memory

with this priority

Foreground process is one that is required for what the user is

currently doing (UI interaction handling an Intent etc)

Visible process is one holding an Activity that is visible to the user

on-screen but not in the foreground (a foreground window leaves

this visible in the background)

Service process is one holding a Service that is invisible to the

user but is doing something valuable (eg Playing music)

Background process is one holding an Activity that is not currently

visible to the user

Empty process is one that doesnt hold any active application

components It is kept only as a cache to improve startup time the

next time an applications component needs to run

Process priority

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 26: First Steps with Android - An Exciting Introduction

Application Lifecycle

bull Designed to protect battery lifebull Activities live on a stackbull Background activities can be killed at

any momentbull The platform makes it easy for

developers to code applications that are killed at any moment without losing stateo Helps with DoS issues

httpwwwandroidcommediaplatform-architectureandroid-20

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 27: First Steps with Android - An Exciting Introduction

Storage and Persistence

Content Provider

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 28: First Steps with Android - An Exciting Introduction

Building Blocks of an

Application

Resources

Images

Audio files

Constants

Stored in lsquoresrsquo directory

Permissions

Must explicitly ask permission to perform tasks

Access web

Access GPS

Access Contacts

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 29: First Steps with Android - An Exciting Introduction

Project identification

When creating a new project the following must be

provided

Project name

Displayed in Eclipse to differentiate projects

Application name

Activity name

The first screen displayed when the application is launched

Package name

comcsci153name

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 30: First Steps with Android - An Exciting Introduction

Project components

Automatically created

AndroidManifestxml

Referenced libraries

Important directories

gen (generated)

res (resources)

src (source)

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 31: First Steps with Android - An Exciting Introduction

Project components

AndroidManifestxml

Global settings

Permissions

Activities

Intents

Referenced libraries

androidjar ndash standard Android library

can add other user-defined libraries

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 32: First Steps with Android - An Exciting Introduction

Project components

gen directory

Contains Rjava

Automatically generated file

Contains pointers to other files and folders

Never modified by programmer

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 33: First Steps with Android - An Exciting Introduction

Project components

res directory

Contains other folders

drawable

Contains image files (icons background)

layout

Contains xml layout files

One for each activity

mainxml is layout for the default activity

values

Contains string pointers that can be used throughout the code

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 34: First Steps with Android - An Exciting Introduction

Project components

src directory

Contains the java source code

One java file for each activity

ltactivitygtjava for the default activity (matches activity name)

xjava for other activities (matches corresponding xml name)

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 35: First Steps with Android - An Exciting Introduction

Manifest File

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 36: First Steps with Android - An Exciting Introduction

Manifest file

AndroidManifestxml

required

Indicates

xml namespace and version

application information

activities

Android SDK version

activities used within the app

services that will be used (Web phone etc)

other aspects

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 37: First Steps with Android - An Exciting Introduction

Example Manifest fileltxml version=10 encoding=utf-8gt

ltmanifest xmlnsandroid=httpschemasandroidcomapkresandroid

package=comexampleshello

androidversionCode=1

androidversionName=10gt

ltapplication androidicon=drawableicon

androidlabel=stringapp_namegt

ltactivity androidname=Hello

androidlabel=stringapp_namegt

ltintent-filtergt

ltaction androidname=androidintentactionMAIN gt

ltcategory androidname=androidintentcategoryLAUNCHER gt

ltintent-filtergt

ltactivitygt

ltapplicationgt

ltuses-sdk androidminSdkVersion=6 gt

ltmanifestgt

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 38: First Steps with Android - An Exciting Introduction

Manifest File

Exploring the ltapplicationgt tag

androidicon=ldquodrawableiconrdquo

Icon to display in the drawer

androidlabel=stringapp_nameldquo

Name of the icon in the drawer

ltactivitygt

child of ltapplicationgt

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 39: First Steps with Android - An Exciting Introduction

Manifest File

Exploring the ltactivitygt tag

androidname=ldquoHellordquo

Associated java file

short for packagenameHello

ie comcsci153examplesHello

androidlabel=ldquostringapp_namerdquo

Text that appears in title bar when this activity is displayed

ltintent-filtergt

child of ltactivitygt

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 40: First Steps with Android - An Exciting Introduction

Manifest File

Exploring the ltintent-filtergt tag

ltaction androidname=androidintentactionMAIN gt

Indicates this is the main entry point of the application

ltcategory androidname=androidintentcategoryLAUNCHER gt

Indicates that the activity should be launched

Without these lines the application is started but no activity is

presented

intent-filters lsquofilterrsquo what an object can do ndash if there is no action defined

within the filter they implicitly deny that the action can be performed

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 41: First Steps with Android - An Exciting Introduction

Intent

Class within Android

androidcontentIntent

contains information regarding some action to be

performed

starting the phone dialer

starting an activity

opening a web page

other

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 42: First Steps with Android - An Exciting Introduction

Intent Example

Starting the phone dialer

Intent intent = new

Intent(IntentACTION_DIALUriparse(tel5551234))

startActivity(intent)

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 43: First Steps with Android - An Exciting Introduction

Intent Example

Opening a web page

Intent intent = new

Intent(IntentACTION_VIEWUriparse

(rdquohttpwwwgooglecomrdquo))

startActivity(intent)

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 44: First Steps with Android - An Exciting Introduction

Intent Example Opening an Activity

Intent intent = new Intent(this Screen2class)

startActivity(intent)

this refers to the current activity

Screen2class refers to the class file associated with the new

activity to be opened

implies a corresponding Sreen2java file exists

activity MUST be referenced in the manifest file

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 45: First Steps with Android - An Exciting Introduction

Intents

Helpful hints about Intents

The intent class has many methods

puthellip to add information to the intent

gethellip to retrieve information from an intent

many others

some of these may provide useful when one Activity launches

another

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 46: First Steps with Android - An Exciting Introduction

Activities

Helpful hints about Activities

Each Activity will have a corresponding xml and java file

Remember to reference each Activity in the manifest file

The Activity class has a method to retrieve the intent that

initiated it (onCreate)

The Activity class has many methods some of which monitor

events associated with it

onhellip (onResume onStop hellip

some of these may provide useful when one Activity launches

another

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 47: First Steps with Android - An Exciting Introduction

httpdeveloperandroidcomreferenceandroidappActivityhtml

public class Activity extends ApplicationContext

protected void onCreate(Bundle savedInstanceState)

protected void onStart()

protected void onRestart()

protected void onResume()

protected void onPause()

protected void onStop()

protected void onDestroy()

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 48: First Steps with Android - An Exciting Introduction

32 IDE and Tools

Android SDKbull Class Librarybull Developer Tools

dx ndash Dalvik Cross-Assembler aapt ndash Android Asset Packaging Tool adb ndash Android Debug Bridge ddms ndash Dalvik Debug Monitor Service

bull Emulator and System Images bull Documentation and Sample Code

Eclipse IDE + ADT (Android Development Tools)bull Reduces Development and Testing Timebull Makes User Interface-Creation easierbull Makes Application Description Easier

3 Software development (2)

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 49: First Steps with Android - An Exciting Introduction

Emulator

bull QEMU-based ARM emulator runs same system image as a devicebull Use same toolchain to work with devices or emulator

3 Software development (2)

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 50: First Steps with Android - An Exciting Introduction

Layouts

Define the user interface for an activity

Layouts are defined in xml files

within reslayout folder

different layout can be designed for landscape view

placed within reslayout-land folder

Handful of layouts to choose from

All derived from the class

androidviewViewGroup

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 51: First Steps with Android - An Exciting Introduction

Layouts Available layouts

AbsoluteLayout

Deprecated as of 15

Allows specific x y coordinates

LinearLayout

Default

Allows child items to be placed in a single row or column

RelativeLayout

Allows child itmes to be placed relative to each other

TableLayout

Allows child items to be placed in multiple rows and columns

FrameLayout

Allows child items to be stacked on one another

We will not cover

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 52: First Steps with Android - An Exciting Introduction

Android

Dalvik Virtual Machine

Androidrsquos equivalent of JVM

Optimized for low memory-management

Written by Dan Bornstein (named after a village where relatives lived)

AVD

Android Virtual Device

Phone Emulation

ADB

Android Debug Bridge

Allows access and control over emulators

DDMS

Dalvik Debug Monitor Service

Middleman between IDE and applications

Communications with ADB to provide control

Telephony

Location

Other

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 53: First Steps with Android - An Exciting Introduction

Building Blocks of an

Application

Activities

User interface screen

Each application can have multiple activities

Layout defined in xml file

Functionality defined in java file

Intents

Intention to perform a task

Explicitly stated in code

Launch an activity

Display a webpage

Broadcast a notification

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 54: First Steps with Android - An Exciting Introduction

Building Blocks of an

Application

Services

Task that runs in the background

Music Player

RSS reader that updates an activity when a site is updated

Content Providers

Bundles data so it can be shared among multiple applications

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 55: First Steps with Android - An Exciting Introduction

httpwwwyoutubecomwatchv=MPukbH6D-lYampfeature=channel

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 56: First Steps with Android - An Exciting Introduction

References

httpwwwyoutubecomwatchv=x1ZZ-R3p_w8

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom

Page 57: First Steps with Android - An Exciting Introduction

Cesar Augusto Nogueira

cesarnogcps

wwwbrazilianswhocodecom