EECE 490V: Introduction to Android Programming

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

10 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

74 εμφανίσεις

EECE
490V: Introduction to Android
Programming
Sunggu
Lee (
이승구
), EE Dept., POSTECH
slee@postech.ac.kr
, 279
-
2236, Eng. 2
-
403
Instructions for Rest of Course

Required
(10/2010) : Get and read the “
andbook
,” an easy
-
to
-
read free online guide to Android programming

[
Gramlich
2010]

Required
(11/2010): Get and read a more complete reference
book on Android programming (note: not free)

[Murphy 2010]

Refer to the online documentation on Android programming

Android developer web site

Android developer forums

Most Important: Write Android applications!

Follow the instructions in the Android programming tutorials

Study the code in the tutorials and the sample apps

Make small modifications to the above code and observe the results

Do the required projects

Ask the TA‟s or the instructor for help
Overview
(rest of material is mostly
based
on [
Gramlich
2010])

Open Handset Alliance (OHA), released Google Android SDK in 2007, stating that

“Android was built … to be truly open. For example, an application could call upon any of the phone's core
functionality such as making calls, sending text messages, or using the camera, allowing developers to create
richer and more cohesive experiences for users.”

“… built on the open Linux Kernel …”

“… Android will be open source …”

Android applications execute within a “register
-
based virtual machine” called the
Dalvik
Virtual Machine (
DalvikVM
)

Similar to, but not the same as a Java VM which is stack
-
based

“… an interpreter
-
only virtual machine that executes files in the
Dalvik
Executable (*.dex) format, a format that is optimized for
efficient storage and memory
-
mappable
execution …”

Java classes can be run in
DalvikVM
after conversion using the “
dx

tool, which is included

Using the libraries and tools provided with Android,
Gramlich
claimed that he was able to develop a
“navigation

driving directions” app in just 1.5 hours!
Building Blocks of an Android App

Note: app

a commonly used abbreviation for

smartphone
application”

Four main building blocks

Activity

Intent / Intent
Receiver

Service

Content Provider

All components necessary in an Android App are listed in
a special file called
AndroidManifest.xml

An XML (
eXtended
Markup Language) file used to declare the
application components and their capabilities and requirements
Aside

Brief Explanation
of XML

In “parsing” (reading a text file and then interpreting the data for use in a
program), it is
extremely useful
if a
standard format
with easily identifiable
tags
are used

E.g., regular text file for Logic Simulator (Project P1) is very
tedious
to read in
and then use in the Logic Simulator program

A lot of switch and if

else if

else if … sequences required

A
“special” text file with simple “
tags
” is much easier to use

E.g.,
<
signal
name=“t1”
value
=“0”
time
=“100” />

Program that “parses” this input would do the following

Read one character at a time until it sees the „<„ character, read a string (=signal) and then call a subroutine
to handle a “signal” object

Subroutine to read in “signal” data then reads in strings separated by whitespace, “=“, or “/>” (return from
subroutine on this last type of string)

XML is a
standard
language for representing data [
Deitel
2002]

Many specialized languages can be created using XML

thus, XML is an
“extensible”
language

XHTML is the extension of XML used for web pages

XML parsers are available for most modern programming languages

Java includes many classes that can be used to work with XML files

E.g., look at
javax.xml.parsers
Activity

Most commonly used building block, starting point of the application

Implemented by defining a class that extends the
Activity
base class

(1) Displays a user interface consisting of one or more
View
s

(2) Responds to events

Keyboard inputs, touch events, event messages from other objects, etc.

User interface is usually implemented using “screens”

Typical application is composed of multiple screens

Each screen is implemented as an
Activity

Application moves around from screen to screen based on user actions

E.g., one screen used to ask for user input, another screen used to display the structure
created by the user input, etc.

Moving to a new screen involves starting a new
Activity

An
Activity
can return a value to a previous
Activity

When new screen opens, previous screen goes onto history stack

User can navigate backwards through
preiiously
opened screens
Intent

A special class used to move from screen to screen

An Intent describes what an application wants done

Important parts of an Intent data structure

The action to perform

MAIN, (go to the starting screen) VIEW, PICK, EDIT, etc.

The data to act on

expressed using URI (uniform resource indicator)
format

A URI can be a URL (uniform resource locator

like a web address) or a URN
(uniform resource name

a string used to define a item‟s identity)

Intent example in text

new Intent(
android.content.Intent.
VIEW_ACTION
,
ContentURI.create
("http://anddev.org"));

Related class

IntentFilter

Defines the Intents that an Activity is capable of handling

This information is included in AndroidManifest.xml

Intent used to move from screen to screen

startActivity
(
myIntent
);
IntentReceiver

Used when code should execute in response to external
events

Events such as phone ringing, SMS text received, data network
is available, time=midnight

Can be registered in AndroidManifest.xml at beginning or
registered by calling
Context.registerReceiver
( );

Application does NOT have to be running for an
IntentReceiver
to be called

An application can broadcast an Intent with
Context.broadcastIntent
( );
Service

Code that can execute for a long time in the background
(“long
-
lived”) and runs without a User Interface

Book‟s example: a media player that plays songs from a play list

An Activity in the media player application can call a service to
start playing songs from a play list

Context.startService
( );

Songs play in the background

songs continue to play even when the
user moves to other screens

User can connect to a Service (or start it) by calling
Context.bindService
( );

When connected, an interface provided by the Service can be
used to perform operations on the Service such as “pause”
ContentProvider

A class that provides a standard set of methods that allow
several applications to SHARE data

Using these methods, any application can store and retrieve the data
supported by that
ContentProvider

E.g., address book data may need to be shared by all applications that
need to use address data

This sharing can occur “automatically” after it has been set up
properly

Other methods that can be used to store and retrieve data

A simple text file

However, retrieving data (parsing the file) is non
-
standardI

An XML format file,

standard XML file access classes can be used for storage/retrieval

An SQL (Structured Query Language) database

A standard “relational database” language

useful for bank account data,
student record data, etc.
Android User Interface

An Android user interface can be built using

(1) Java code or

(2) XML

Can be used to define a graphical user interface (GUI) easily

XML provides a standard format for describing GUI objects

A set of predefined tags are used

the Android system knows how to
interpret those tags to create standard GUI objects (buttons, text entry
boxes, clocks, etc.)

An Android XML file is well
-
structured and follows a tree structure

A tag can be defined within another tag, which is also defined within
another tag, and so on

Refer to the XML files used in Android tutorial and sample programs and
use those files as “templates”

If you don‟t understand all of the elements at first, JUST USE THEM exactly
as they are used in the examples (just change the minimum parts
necessary for your application)
Tree Structured UI

Tree of “Views”

A screen image (presented to the user as a user interface (UI))
can be defined as a “Tree of Views and
Viewgroups


View

A class that defines a “screen” to be viewed by a user

This may include a user interface with user input and output

A view can span the entire phone screen, just part of the phone
screen, or be larger than the phone screen (resulting in scroll bars)

Viewgroup

A class that is used to define a set of views as one element

To display a tree of View and
Viewgroup
objects, application
program calls

setContentView
(“root of tree
-
structured UI”);
List of Useful References

Nicolas
Gramlich
,
andbook
: Android Programming

with Tutorials from the
anddev.org
-
Community
, 2010. Online.
http://andbook.anddev.org

Good (free) introductory textbook

M. L. Murphy,
Beginning Android 2
,
Apress
, New York, March 2010.

Textbook to be used in the last 1/3 part of the course

Needs to be purchased separately, as a paperback or as a PDF file

Lauren
Darcey
and Shane
Conder
,
SAMS
Teach Yourself Android
Application Development in 24 Hours, SAMS Publishing, Indianapolis, 2010.

Another useful reference textbook on Android App Development

Android Developer Site,
http://developer.android.com/index.html

Use this site for basic tutorials, sample programs, Android class documentation

Android Developer 101 Forum,
http://androidforums.com/developer
-
101/

Use this and similar sites for helpful Android app development
information

H. M.
Deitel
, P. J.
Deitel
and T. R. Nieto,
Internet and World Wide Web: How to
Program, 2
nd
Ed.
, Prentice
-
Hall, Upper Saddle River, 2002.
13