You are on page 1of 24

Google Android

Based on android-sdk_2.2

Mobile Computing

Bruce Scharlau, University of Aberdeen, 2010


Android is part of the ‘build a
better phone’ process
Open Handset Alliance produces
Android

Comprises handset manufacturers,


software firms, mobile operators, and
other manufactures and funding
companies

http://www.openhandsetalliance.com/

Bruce Scharlau, University of Aberdeen, 2010


Android is growing
Uneven distribution of OS by regions

Does not include iTouch or iPad, as not smartphones

http://metrics.admob.com/wp-content/uploads/2010/06/May-2010-AdMob-Mobile-Metrics-Highlights.pdf
Bruce Scharlau, University of Aberdeen, 2010
Android makes mobile Java easier

Well, sort of…

Bruce Scharlau, University of Aberdeen, 2010


http://code.google.com/android/goodies/index.html
Android applications are written
in Java
package com.google.android.helloactivity;

import android.app.Activity;
import android.os.Bundle;

public class HelloActivity extends Activity {


public HelloActivity() {
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.hello_activity);
}
}

Bruce Scharlau, University of Aberdeen, 2010


Android applications are
compiled to Dalvik bytecode
Write
Write app
app in
in Java
Java
Compiled
Compiled in
in Java
Java

Transformed
Transformed to
to Dalvik
Dalvik bytecode
bytecode

Loaded
Loaded into
into Dalvik
Dalvik VM
VM

Linux OS

Bruce Scharlau, University of Aberdeen, 2010


The Dalvik runtime is optimised
for mobile applications

Run multiple VMs efficiently

Each app has its own VM

Minimal memory footprint


Bruce Scharlau, University of Aberdeen, 2010
Android has many components

Bruce Scharlau, University of Aberdeen, 2010


Can assume that most have
android 2.1 or 2.2

Bruce Scharlau, University of Aberdeen, 2010


http://developer.android.com/resources/dashboard/platform-versions.html
Android has a working emulator

Bruce Scharlau, University of Aberdeen, 2010


All applications are written in
Java and available to each other

Android designed to enable reuse of


components in other applications

Each application can publish its


capabilities which other apps can use

Bruce Scharlau, University of Aberdeen, 2010


Android applications have
Views
Views such
such as
as common structure
lists,
lists, grids,
grids, text
text An
An Activity
Activity Manager
Manager that
that
boxes,
boxes, buttons,
buttons, manages
manages the
the life
life cycle
cycle of
of
and
and even
even an
an applications
applications and
and provides
provides
embeddable
embeddable web web aa common
common navigation
navigation
browser
browser backstack
backstack
Content
Content A
A Notification
Notification Manager
Manager
Providers
Providers that
that that
that enables
enables all
all apps
apps toto
enable
enable display
display custom
custom alerts
alerts in
in the
the
applications
applications toto status
status bar
bar
access
access data
data from
from
other
other applications
applications A
A Resource
Resource Manager,
Manager,
(such
(such as
as providing
providing access
access toto non-
non-
Contacts),
Contacts), oror to
to code
code resources
resources such
such asas
share
share their
their own
own localized
localized strings,
strings,
data
data graphics,
graphics, and
and layout
layout files
files
Bruce Scharlau, University of Aberdeen, 2010
Android applications have
common structure
Broadcast
Broadcast Activity
Activity isis the
the presentation
presentation
receivers
receivers can
can layer
layer of
of your
your app:
app: there
there will
will
trigger
trigger intents
intents that
that be
be one
one per
per screen,
screen, and
and the
the
start
start an
an application
application Views
Views provide
provide the
the UI
UI to
to the
the
activity
activity
Data
Data storage
storage
provide
provide data
data for
for Intents
Intents specify
specify what
what
your
your apps,
apps, and
and specific
specific action
action should
should be
be
can
can be
be shared
shared performed
performed
between
between apps
apps ––
database,
database, file,
file,
and
and shared
shared Services
Services run run in
in the
the
preferences
preferences background
background and and have
have
(hash
(hash map)
map) used
used no
no UI
UI for
for the
the user
user ––
by
by group
group of
of they
they will
will update
update data,
data,
applications
applications and
and trigger
trigger events
events

Bruce Scharlau, University of Aberdeen, 2010


There is a common file structure
for applications
code
Autogenerated
files resource list
images

UI layouts

constants

Bruce Scharlau, University of Aberdeen, 2010


Standard components form
building blocks for Android apps
Notifications
Has life-cycle
Activity
screen
Views
App to handle content
Intents
Background app
Service Like music player

manifest

ContentProviders Other applications


Bruce Scharlau, University of Aberdeen, 2010
The AndroidManifest lists
application details
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my_domain.app.helloactivity">
<application android:label="@string/app_name">
<activity android:name=".HelloActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category
android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

Bruce Scharlau, University of Aberdeen, 2010


Activity is one thing you can do

Bruce Scharlau, University of Aberdeen, 2010


From fundamentals page in sdk
Intent provides late running
binding to other apps

It can be thought of as the glue between


activities. It is basically a passive data
structure holding an abstract description of
an action to be performed.

Written as action/data pairs such as:


VIEW_ACTION/ACTION content://contacts/1

Bruce Scharlau, University of Aberdeen, 2010


Services declared in the manifest
and provide support
Services run in the background:
Music player providing the music playing in
an audio application

Intensive background apps, might need to


spawn their own thread so as to not block
the application
Bruce Scharlau, University of Aberdeen, 2010
Notifications let you know of
background events
This way you know that an SMS arrived,
or that your phone is ringing, and the
MP3 player should pause

Bruce Scharlau, University of Aberdeen, 2010


ContentProviders share data

You need one if your application shares data


with other applications

This way you can share the contact list with the
IM application

If you don’t need to share data, then you can


use SQLlite database

Bruce Scharlau, University of Aberdeen, 2010


UI layouts are in Java and XML

setContentView(R.layout.hello_activity); //will load the XML UI file


Bruce Scharlau, University of Aberdeen, 2010
Security in Android follows
standard Linux guidelines
Each application runs in its own process
Process permissions are enforced at user
and group IDs assigned to processes
Finer grained permissions are then
granted (revoked) per operations

<manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.app.myapp"
package="com.google.android.app.myapp" >>
<uses-permission
<uses-permission id="android.permission.RECEIVE_SMS"
id="android.permission.RECEIVE_SMS" /> />
</manifest>
</manifest>
Bruce Scharlau, University of Aberdeen, 2010
There are lots of sources of
information
• The sdk comes with the API references,
sample applications and lots of docs
• Blog http://android-developers.blogspot.com/
which has lots of useful examples, details
• There is http://www.anddev.org

Bruce Scharlau, University of Aberdeen, 2010

You might also like