Android Development

baroohspottyΚινητά – Ασύρματες Τεχνολογίες

19 Ιουλ 2012 (πριν από 4 χρόνια και 10 μήνες)

353 εμφανίσεις


Huang Xuguang
xuguangmit@gmail.com
2009.11.10
Android Development
Basic Widget
Outline

Development environment

User Interface

Intents

Service

jdk
-
6u17
-
windows
-
i586.exe

http://java.sun.com/javase/downloads/
index.jsp
Development environment

eclipse
-
java
-
galileo
-
SR1
-
win32.zip

http://www.eclipse.org/downloads/download.p
hp?file=/technology/epp/downloads/release/gali
leo/SR1/eclipse
-
java
-
galileo
-
SR1
-
win32.zip

android
-
sdk_r3
-
windows.zip

http://developer.android.com/
intl
/
zh
-
CN/
sdk
/index.html
Case:
HelloWorld
!

Activity

Your application’s presentation
layer

It uses View to form graphical
user interface

Resources

Strings, colors, styles and
graphics…

Manifest file

It describes where your
application begins, what its
permissions are, and what
activities(services and receivers)
User Interface
Developer:
Conductor
Activity
Activity:
Symphony
View:
Musicians
Resource:
Musical
Instrument,
Music score…

Creating an Activity class
Creating the Activity

Applications run in their own processes

Every process is placed on a stack

Processes are started and stopped as needed to run an
application’s components

Processes may be killed to reclaim resources
The process hosting the foreground Activity
Any process hosting a visible but not foreground Activity
Any process hosting a background Activity
Any process not hosting any Activity
Priorities
Activity Lifecycle(1/2)
Called when the Activity is
created. Be access to any
previously stored state.
Called if the activity is being
restarted or starting a new
one if it is still in the stack.
Called when the Activity is
becoming visible
Called when the Activity
starts interacting with the
user.
Called when the Activity is
pausing or reclaiming CPU
and other resources.
Called to stop the Activity
and transition it to a
nonvisible phase and
subsequent lifecycle events.
Called when the Activity is
being removed.
onCreate()
onRestart()
onStart
()
onResume
()
onPause
()
onStop
()
onDestroy
()
Activity Lifecycle(2/2)

An activity contains a
hierarchical tree
of View
elements

Many kinds of views: text elements, input elements,
images, buttons, and your own views

Be placed into Activity by
directly code
or
XML
resource

Fundamental aspects of views

Common views

Custom views

Layout in relation to views

Event handling
Views

Common view objects are in
the
androd.view
package
.

Android doc.:
http://code.google.com/andro
id/reference/view
-
gallery.html

A set of methods in the base
Android View API

setBackgroundColor
(
int
color)

setMinimumHeight
(
int
minHeight
)

Android
Javadocs
:
http://code.google.com/andro
id/reference/android/view/Vie
w.html
Common Views

Screen layout is defined in
terms of
ViewGroup
and
LayoutParams
objects
.

ViewGroup is a View that
contains other views

The root of every
hierarchical tree of every
screen is a ViewGroup

LayoutParams

An exact number

FILL_PARENT

WRAP_CONTENT
Understanding Layout

Resources are
non
-
code items
that are included with
your project automatically by the platform

Supported resource types

res/
anim

XML representations of frame
-
by
-
frame
animations

res/
drawable

.png,.9.png, and .jpg images

res/layout

XML representations of View objects

res/values

XML representations of strings, colors, style,
dimensions and arrays

res/xml

User
-
defined XML files(that are also compiled
into a binary form)

res/raw

Arbitrary and
uncompiled
files that can be
added
Resources

Views and layout are often
defined in XML rather
than in Java code

Defining views and layouts
as resources: easier to
work with, decoupled
from the code and
reusable in different
contexts.

Path of resource files:
res/layout

As many XML layout/view
files as needs

Each View is then
referenced in code based
on
type
and
ID
.
<RelativeLayout
android:layout_height
android:id
=“@+id/
review_image

android:layout_below
=“@id/
review_image

@id
syntax
is a way to reference other resource
items from within a current resource file
Defining views and layout

AndroidManifest.
xml

It describes the
application
context and any
supported
activities,
services, intent
receivers, and/or
content providers,
as well as
permissions.
AndroidManifest
file

Supported AndroidManifest.xml elements
AndroidManifest
file

Intent and Service objects run on the back end

Activity and View objects run on the front end

Intent classes are the communications network of
the applications on Android platform

“hand off to another component to perform the
next task”

Request(Activity)
---
intent
---
Response(component)

How to define an Intent

How an Intent is invoked

How Intent takes place using
IntentFilter
classes
Intent

Intents are made up of:

Action: Fully qualifies
String
indicating action

E.g.:
android.intent.action.MAIN

Categories: Additional
metadate
about Intent

E.g.:
android.intent.category.LAUNCHER

Data: Data to work with expressed as a
Uri
object

Additional set of optional elements
Defining Intents

Two ways to call up an Intent

Implicit Intent invocation

Explicit Intent invocation
Invoking Intent

<intent
-
filter> element

AndroidManifest.xml file

Each <intent
-
filter> is parsed into an
IntentFilter
object

Two rules to match
Intent
to
IntentFilter

Action
and
category
must match

If specified, the
data
type must match
Intent resolution

Services are background processes

Rather than UI screens

Be invoked with a call to action

Purpose:

For a longer
-
running background process

Screen
-
to
-
screen foreground applications

Exposing a remotable object for IPC(
进程间通信
)
Service
Front end: Notification
-
based window
Service:
WeatherAlertService

Environment

User Interface

Activity

Creating

LifeCycle

View

Resource

AndroidManifest

Intent and Service
Summary

Develop an Address book application

Java &
Eclipse

Develop an Address Book app. running on
Android

Consulting your mobile phone to design a
User Interface for your Address Book app..
Practices

Thank you!

Q & A