View
220
Download
0
Category
Preview:
Citation preview
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
1/42
Programming with Android:System Architecture
MELJUN P. CORTES,MBA,MPA,MSCS in pro
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
2/42
MELJUN P. CORTES- Programming with Android – System Architecture
Outline
Android Components: Content Providers
Android Components: Services
Android Components: Intents
Android Components: Activities
Android Dalvik Java Virtual Machine
Android Architecture: An Overview
Android Application Distribution and Markets
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
3/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android … What?
Android is a Linux-based platform fo
devices …
Operating System
Middleware
Applications
Software Development Kit (SDK)
Which kind of mobile devices … (exa
SMARTPHONES TABLETS EREADERS ANDROID TV GOOGLE GLASSES
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
4/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android … What?
SMARTPHONES TABLETS EREADERS ANDROID TV GOOGLE GLASSES
SMART FRIDGE
ANDROID MICROW
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
5/42MELJUN P. CORTES- Programming with Android – System Architecture
Android … When?
Google buys Android from the Android In
Open Handset Alliance (OHA) created for
standards for mobile devices. Partners of OHGoogle, Motorola, Samsung, Vodafone, T-Mobile
Android 1.0 Released
The first Android smartphone: G1 HTC-Drea
Android 1.1 Released
Android 1.5 (CupCake) Released
2005
2006
2007
2008
2009
Time
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
6/42MELJUN P. CORTES- Programming with Android – System Architecture
Android … When?
Android 1.6 (Donut) Released
Android 2.0 (Eclair ) Released
Android 2.2 (Froyo) Released
Android 2.3 (Gingerbread) Released
Android 3.0 (Honeycomb) Released(First version for devices with larger screens such as tablets
Android 4.0 (Ice-Cream Sandwich) Relemerges the 3.x tab centric design and the v2.x phone bas
into a single version.)
2008
2009
2010
2011
2012
Time
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
7/42MELJUN P. CORTES- Programming with Android – System Architecture
Android … When?
Android 4.4 (Kitkat) Released
Wireless printing capability
Ability for applications to use "immersive mod
Performance optimization
New experimental runtime virtual machine, A
API Level 19 (Android 4.4):
Support to new embedded sensors (e.g. STEP_DETECTOR)
Adaptive video playback functionalities
Read and write SMS and MMS messages
(managing default text messaging client)
2012
2013
Time
ANDROID 5.0
2014
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
8/42MELJUN P. CORTES- Programming with Android – System Architecture
Android … When?
2012 Market Share 2013 Market Sharewww.gartner.com
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
9/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android … When?
h t t p : / / o p e n s i g n a l . c o m / r e p o r t s / f r a g m e n t a t i o n - 2 0 1 3 /
11,868 different devices in 2013!
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
10/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android … When?
http://developer.android.com/about/dashboards/index.
Updated at February 2014
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
11/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android … When?
ANDROID VER
HISTORY AND PO
(2009-201
http://en.wikipedia.org/wiki/Android_version_history
4.x
2.3.x
2.2.x
1.6-2.0
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
12/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android … When?
http://www.appbrain.com/stats/android-market-app-categories
ANDROID APP CATEGORIES
http://www.onlinemarketing-trends.com/2011
marketplace-top-5-statistics.html
ANDROID APP PRICE
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
13/42
MELJUN P. CORTES- Programming with Android – System Architecture
The Android Architecture
} S ArchOpen Source
(Apache/MIT L
Business-frien
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
14/42
MELJUN P. CORTES- Programming with Android – System Architecture
The Android Architecture
Built on topkernel (v. 2
Advantages:
Portabilitycompile on di
hardware arc
Security (e.multi-process
Power Man
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
15/42
MELJUN P. CORTES- Programming with Android – System Architecture
The Android Architecture
Native Libr
(C/C++ code)
Graphics (Su
Multimedia (
Database DB
Font Manag(FreeType)
WebKit
C libraries (B
….
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
16/42
MELJUN P. CORTES- Programming with Android – System Architecture
The Android Architecture
Application(Core Components
Activity Man
Packet Mana
Telephony M
Location Ma
Contents Pr
Notification
….
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
17/42
MELJUN P. CORTES- Programming with Android – System Architecture
The Android Architecture
Applicatio(Written in Java co
Android Pla
Entertainme
Productivity
Personalizat
Education
Geo-commu
….
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
18/42
MELJUN P. CORTES- Programming with Android – System Architecture
The Android Architecture
Dalvik Virt
Machine (V
Novel Java V
Machine imple
(not using the O
Open Licens
JVM is not ope
Optimized fo
constrained de
Faster than O
….
l ik i l hi ( )
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
19/42
MELJUN P. CORTES- Programming with Android – System Architecture
Dalvik Java Virtual Machine (JVM)
Java Source
Code
Java Byte
Code
Java Virtual
Machine (JVM)
Java Source
Code
Java Byte
Code
Dalvik Byte
Code
Dalvik Virtual
Machine (VM)
Java
Compiler
Java
Compiler
Dex
Compiler Stack-based
byte-code
Register-
byte-code
Java Standard Edition
A d id A li i D i
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
20/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Applications Design
GUI Definition
Events Management
Application Data Manageme
Background Operations
User Notifications
APPLICATION DESIGN:
A d id A li ti D i
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
21/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Applications Design
Activities & Fragments
Intents
Services
Content Providers
Broadcast Receivers
APPLICATION COMPONENTS
A d id C t A ti iti
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
22/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Activities
An Activity corresponds to a single
of the Application.
An Application can be composed of
screens (Activities).
The Home Activity is shown when tlaunches an application.
Different activities can exhange info
one with each other.
Hello World!
Android HelloWorld
Button1
A d id C t A ti iti
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
23/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Activities
Each activity is composed by a list of graphics compo
Some of these components (also called Views) can inwith the user by handling events (e.g. Buttons).
Two ways to build the graphic interface:
Example:
Button button=new Button (this);TextView text= new TextView();text.setText(“Hello world”);
PROGRAMMATIC APPROACH
Android Components: Activities
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
24/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Activities
Each activity is composed by a list of graphics comp
Some of these components (also called Views) canwith the user by handling events (e.g. Buttons).
Two ways to build the graphic interface:
Example:
< extView android.text=@string/hello” android:textcolor=@color/bluandroid:layout_width=“fill_parent” android:layout_height=“wrap_cont< utton android.id=“@+id/Button01” android:textcolor=“@color/blueandroid:layout_width=“fill_parent” android:layout_height=“wrap_cont
DECLARATIVE APPROACH
Android Components: Activities
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
25/42
MELJUN P. CORTES- Programming with Android – System Architecture
- Build the application layou
through XML files (like HTML
- Define two different XML la
for two different devices
- At runtime, Android detects
current device configuration
loads the appropriate resoufor the application
- No need to recompile!
- Just add a new XML file if y
need to support a new devi
EXAMPLE
Device 1HIGH screen pixel density
Device 2LOW screen pixel density
XML Layout FileDevice 1 XML Layout FileDevice 2
Java App Code
Android Components: Activities
Android Components: Activities
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
26/42
MELJUN P. CORTES- Programming with Android – System Architecture
EXAMPLE
Device 1HIGH screen pixel density
Device 2LOW screen pixel density
XML Layout FileDevice 1 XML Layout FileDevice 2
Java App Code
Android Components: Activities
http://developer.android.com/about/dashboards/index
SCREEN CONFIGURATION DISTRIBUTION
Android Components: Activities
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
27/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Activities
Android applications typically use both the approach
DECLARATIVE APPROACH
PROGRAMMATIC APPROACH
Define the Application layou
resources used by the App
(e.g. labels).
Manages the events, and h
the interaction with the use
XML Code
Java Code
Android Components: Activities
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
28/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Activities
Views can generate events (caused by human inter
that must be managed by the Android-developer.
public void onClick(View arg0) {if (arg0 == Button) {
// Manage Button events}
}
ESEMPIO
B u t t o n
T e x t E d i t
Android Components: Activities
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
29/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Activities
The Activity Manager is responsib
creating, destroying, managing acti
Activities can be on different states
starting , running , stopped , destroye
paused .
Only one activity can be on the run
state at a time.
Activities are organized on a stack
have an event-driven life cycle (detai
Android Components: Activities
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
30/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Activities
Main difference between Android-programming and Jav
-programming:
Mobile devices have constrained resource capab
Activity lifetime depends on users’ choice (i.e. change
visibility) as well as on system contraints (i.e. memoryshortage).
Developer must implement lifecycle methods to accou
state changes of each Activity …
Android Components: Activities
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
31/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Activities
public class MyApp extends Activity {
public void onCreate() { ... }
public void onPause() { ... }
public void onStop() { ... }
public void onDestroy(){ ... }
….
}
Called when the
is created the f
Called when the
is partially visi
Called when th
is no longer v
Called when th
is dismissed.
Android Components: Intents
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
32/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Intents
Intents: asynchronous messages to activate core A
components (e.g. Activities).
Explicit Intent The component (e.g. Activity1) spec
destination of the intent (e.g. Activity 2).
LOGIN
PASSWORD
Login
marco
**********
Welcome Marco!
Login Intent
A c t i v i t y 1
A c t i v i t y 2
Android Components: Intents
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
33/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Intents
Intents: asynchronous messages to activate core A
components (e.g. Activities).
Implicit Intent The component (e.g. Activity1) spec
type of the intent (e.g. “ View a video” ).
View
Implicit Intent A c t i v i t y 1
A c t i v i t y 2
A c
t i v i t y 2
Multiple choices
might be availableto the user! }
Android Components: Services
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
34/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Services
Services: like Activities, but run in background and
provide an user interface.
Used for non-interactive tasks (e.g. networking).
Service life-time composed of 3 states:
Starting Destroyed
Running
(on background)
onCreate()
onStart()onDestroy()
Android Components: Content Provi
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
35/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Content Provi
Each Android application has its own private set o
(managed through files or through SQLite database).
Content Providers: Standard interface to access a
share data among different applications.
DB
APP
insert()
update()
delete()
query()
Content
Provider
e.g. P
Android Components: Broadcast Rece
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
36/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android Components: Broadcast Rece
Publish/Subscribe
paradigm
Broadcast Rece
An application ca
signaled of extern
events.
Notification type
incoming, SMS
delivery, Wifi netw
detected, etc
Android Components: Broadcast Rece
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
37/42
MELJUN P. CORTES- Programming with Android – System Architecture
d o d Co po e ts oadcast ece
class WifiReceiver extends BroadcastReceiver {
public void onReceive(Context c, Intent intent) {String s = new StringBuilder();
wifiList = mainWifi.getScanResults();
for(int i = 0; i < wifiList.size(); i++){
s.append(new Integer(i+1).toString() + ".");
s.append((wifiList.get(i)).toString());
s.append("\\n");
}
mainText.setText(sb);
}
}
BROADCAST RECEIVER example
Android Components: System API
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
38/42
MELJUN P. CORTES- Programming with Android – System Architecture
p y
Using the components described so far, Android
applications can then leverage the system API …
Telephony Manager data access (call, SMS, etc)
Sensor management (GPS, accelerometer, etc)
Network connectivity (Wifi, bluetooth, NFC, etc)
Web surfing (HTTP client, WebView, etc)
Storage management (files, SQLite db, etc)
….
SOME EXAMPLEs …
Android Components: Google API
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
39/42
MELJUN P. CORTES- Programming with Android – System Architecture
p g
… or easily interface with other Google services:
Android Application Distribution
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
40/42
MELJUN P. CORTES- Programming with Android – System Architecture
Each Android application is
contained on a single APK fi Java Byte-code (compiled fo
Dalvik JVM )
Resources (e.g. images. videXML layout files)
Libraries (optimal native C/C+
code)
APKFILE
XML
FilesC
Android Application Distribution
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
41/42
MELJUN P. CORTES- Programming with Android – System Architecture
pp
Each application must be sig
through a key before being
distributed.
Applications can be distribu
via Web or via Stores.
Android Play Store: applica
store run by Google … but s
other application stores are
available (they are just norm
applications).
Android Application Security
8/20/2019 MELJUN CORTES ANDROID Lecture Architecture
42/42
MELJUN P. CORTES- Programming with Android – System Architecture
Android applications run with a distinct system iden
(Linux user ID and group ID), in an isolated way.
Applications must explicitly share resources and da
They do this by declaring the permissions they ne
additional capabilities.
Applications statically declare the permissions they requ
User must give his/her consensus during the installatio
Recommended