The slides we saw at the Android Code Camp 2012. The course was held in Urbino, at the headquarters of the degree course "Informatica Applicata" (Computer Science), University of Urbino "Carlo Bo".
2. Android Code Camp, Urbino — 2012.
Theory overview.
The smartphone market.
The Android project.
Android architecture.
The ecosystem.
Application overview.
Structure of an Android project.
Hands-on: setting up the development
environment.
„Hello World.―
3. Android Code Camp, Urbino — 2012.
Mobile market.
The smartphone market.
Numbers and growth.
The Android market.
Activations.
Application marketplace.
Fragmentation.
4. Android Code Camp, Urbino — 2012.
The smartphone market.
433 milions of units in 2011.
616 milions of units forecast for 2012.
• Market growth (contractino of feature
phone sales).
• Product obsolescence.
Tablets: 320 milions of units in 2015.
7. Android Code Camp, Urbino — 2012.
The Android market.
Astounding growth (+106% forecast).
Mainly Samsung devices:
Up to 33% of all devices.
2012:
500 milions of devices activated.
1.3 milions of peak activations per day.
9. Android Code Camp, Urbino — 2012.
Application market.
Android < iOS:
More than 400.000 applications,
against 500.000 apps for iOS.
• Google Play
• Amazon AppStore for Android
• Other stores: GetJar, AppBrain, etc.
10. Android Code Camp, Urbino — 2012.
Application market.
Android < iOS:
Only ¼ of revenue, on average.
Different market segment / users.
Almost 70% of applications are free
or follow the freemium model
(against 50% on iOS).
The fragmentation issue.
13. Android Code Camp, Urbino — 2012.
Android.
Google‘s mobile OS.
History.
Versions and evolution.
The open-source project.
14. Android Code Camp, Urbino — 2012.
A short history of Android.
2003: Andy Rubin founds ―Android Inc‖.
“...smarter mobile devices that are more aware of
its owner's location and preferences.”
2004: Apple starts ―Project Purple‖,
a secret project with AT&T.
2005: Google buys out Android Inc and
continues the devlopment of the OS.
15. Android Code Camp, Urbino — 2012.
A short history of Android.
2007, jan: Apple releases the first iPhone.
2007, nov: Google, HTC, Samsung reveal
the Open Handset Alliance & Android.
2008: first Android phone:
HTC Dream (G1).
19. Android Code Camp, Urbino — 2012.
Android: openness.
October 2010, Steve Jobs:
„Google likes to characterize
Android as open and iOS as
closed. We think this is
disingenuous. […] The real
difference is integrated
versus fragmented.”
21. Android Code Camp, Urbino — 2012.
Android: open-source project.
The code of Android is available under
„free― and „open-source― licenses.
Linux kernel (Open Handset Alliance):
GNU GPL v2, public development.
Android system (Google):
Network, telephony, Google apps.
Apache License v2.0, private.
22. Android Code Camp, Urbino — 2012.
Android: open-source project.
Production of a „flagship phone― by Google
(Nexus), is followed by release of code
(and OEM phones).
Google Play is available on certification.
„Honeycomb incident― (2011).
License is incompatible with GPL (FSF).
23. Android Code Camp, Urbino — 2012.
The architecture.
Operating System architecture
Linux Kernel.
Native libraries.
Android Runtime.
Dalvik Virtual Machine.
Core Libraries.
Application framework.
Application layer.
25. Android Code Camp, Urbino — 2012.
Linux Kernel.
Kernel 2.6+.
Used for process and thread
management, low-level memory
management, the network
stack, security, for the driver model.
26. Android Code Camp, Urbino — 2012.
Native libraries.
C/C++ libraries executed on top of the
Linux kernel and used in many fields of the
Android system.
They expose a lot of funcionalities to
developers through the application
framework.
27. Android Code Camp, Urbino — 2012.
Android Runtime.
It makes an Android device much different
from a mobile Linux implementation.
Combining the Dalvik Virtual Machine and
the Core Libraries makes possible the
execution of Android applications.
28. Android Code Camp, Urbino — 2012.
Virtual machine.
Software implementation of a machine
(with a defined Instruction Set Architecture)
that executes programs like a physical
machine.
Virtualization: simulation of an environment
where Guest ISA and Host ISA match.
Emulation: simulation of an environment
where Guest ISA and Host ISA are
different.
29. Android Code Camp, Urbino — 2012.
Java virtual machine.
Virtual machine that executes programs
written in byte-code: intermediate
rappresentation between machine
language and Java source code.
JVM is an Oracle (ex Sun) specification.
Main implementations:
HotSpot – OpenJDK (GPL).
HotSpot – OracleJDK.
30. Android Code Camp, Urbino — 2012.
Dalvik virtual machine.
Virtual machine that executes .dex (Dalvik
Executable) files.
Java source code compiled in .class files
and converted to .dex format.
Each Android application runs in a
separate process within its Dalvik virtual
machine instance.
JIT compiler (since version 2.2).
31. Android Code Camp, Urbino — 2012.
Dalvik vs. JVM.
Dalvik < JVM.
But it is a multidimensional problem.
• Register-based.
• Efficient with multiple VMs.
• Minimum
memory
footprint.
• Small
startup time.
32. Android Code Camp, Urbino — 2012.
Core libraries.
Dalvik does not comply with either the
J2SE specifications, nor the J2ME.
Core libraries provide most of the
functionalities available through the Java
libraries, as well as Android specific
libraries.
33. Android Code Camp, Urbino — 2012.
Application framework.
Provides key services, encapsulated in
Java objects, to the applications of the
above level.
These services are available for both
system applications and for third party
applications.
34. Android Code Camp, Urbino — 2012.
Application layer.
User level applications written in Java
language.
System app
=
Third party App
35. Android Code Camp, Urbino — 2012.
The ecosystem.
Development ecosystem.
Android SDK.
Eclipse IDE.
Application Programming Interfaces.
36. Android Code Camp, Urbino — 2012.
SDK: emulator.
Software that emulates the function and
appearance of a virtual hardware
configuration (AVD: Android Virtual
Device).
38. Android Code Camp, Urbino — 2012.
SDK: tools.
Logcat: collects logs of an Android device.
Lint: static analisys to optimize and detect
common mistakes.
Proguard: reduce binary size, optimize
and obscure given code. It makes
applications faster and more resilient to
reverse engineering.
39. Android Code Camp, Urbino — 2012.
SDK: Dalvik Debug Monitor Serve
Debugging tool for Android devices:
gathers information about
processes, threads, heap, logcat and
supports event emulation.
40. Android Code Camp, Urbino — 2012.
SDK: Android Developer Tools.
Plugin for the Eclipse IDE.
It simplifies the creation, compilation and
maintenance of projects.
It integrates development tools.
It includes graphical editors and
documentation.
41. Android Code Camp, Urbino — 2012.
Eclipse.
Open-source development
environment,
multi-platform and
multi-language.
It is the reference
platform for Android.
Alternatives:
ANT, NetBeans…
43. Android Code Camp, Urbino — 2012.
Android 1.5, API 3.
Playback and audio/video capture.
Speech recognition.
Widgets.
Notifications.
WebView.
44. Android Code Camp, Urbino — 2012.
Android 1.6, API 4.
Gestures.
Speech synthetizer.
CDMA support.
Variable size and density screens support.
45. Android Code Camp, Urbino — 2012.
Android 2.1, API 7.
Bluetooth 2.1 support.
Live Wallpapers.
46. Android Code Camp, Urbino — 2012.
Android 2.2, API 8.
JIT compiler.
SD card installation support.
Speech recognition improvement and third
party openness.
Flash technology support.
47. Android Code Camp, Urbino — 2012.
Android 2.3, API 9/10.
Native Voip support (SIP).
NFC support.
Concurrent Garbage Collector.
Improved media format support.
48. Android Code Camp, Urbino — 2012.
Android 3.0, API 11.
Fragments.
ActionBar.
New drag ‗n drop APIs.
2D hardware acceleration support.
New 3D framework renderscript.
Improved media format support.
49. Android Code Camp, Urbino — 2012.
Android 3.1, API 12.
USB peripherals support.
Resizable Widgets.
Improved media format support.
50. Android Code Camp, Urbino — 2012.
Android 4.0.1, API 14.
Smartphone and Tablet merge.
Linux kernel 3.x.
Redesigned UI to enhance coherence and
unification.
More powerful notifications.
Continuous speech recognition support.
Social APIs.
Low level streaming APIs.
51. Android Code Camp, Urbino — 2012.
Android 4.1.3, API 16.
Project Butter.
Expandable notifications.
Improved social APIs.
Advanced speech recognition.
Enhanced speech synthetizer.
Google Now.
Flash technology pulled out.
58. Android Code Camp, Urbino — 2012.
Service.
A task the app or the system does without
directly affecting the UI (a background
task).
Examples:
Gathering data from the system.
Updating data of an app.
Download new RSS feeds from a
server.
59. Android Code Camp, Urbino — 2012.
Service.
It cannot directly communicate with the
user. Though it can exchange data with
activities (which may belong to the same
app or not) and the system.
60. Android Code Camp, Urbino — 2012.
Service.
If a particular service should never be
killed by the system, it should be declared
as a foreground service.
62. Android Code Camp, Urbino — 2012.
Content provider.
• It‘s an abstraction of a set of structured
data.
• Implements the CRUD interface
(create, retrieve, update, and delete).
• Can be also used to share data among
different applications.
Android provides many ready-made
providers. It is also possible to implement
custom providers.
63. Android Code Camp, Urbino — 2012.
Content provider.
Some examples:
• List of contacts.
• List of images on the device.
• Data from a DB SQLite.
• Data from a web service.
65. Android Code Camp, Urbino — 2012.
Broadcast receiver.
Components which are employed for
intra-application / inter-process
communication.
They receive so-called broadcast intents…
66. Android Code Camp, Urbino — 2012.
Intent.
Are the messaging system between
various components of the system.
Each intent represents a structure which
encapsulates data of a message.
An intent can be thought as an abstraction
of:
An operation to execute.
An event which has just happened.
67. Android Code Camp, Urbino — 2012.
Intent.
Possible values:
Field Value
Component name it.uniurb.codecamp.test
Action ACTION_CALL
Data
URI tel:07224475
Type integer
Category CATEGORY_LAUNCHER
Extras "tel_number":int
Flags FLAG_ACTIVITY_SINGLE_TOP
68. Android Code Camp, Urbino — 2012.
Intent.
Send an image:
Field Value
Action SEND
Data content://media/external/pic16
Show a spot by Google Maps:
Field Value
Action VIEW
Data geo:latitude,longitude?z=zoom
69. Android Code Camp, Urbino — 2012.
Intent.
The sender is always known,
the receiver may be unknown.
70. Android Code Camp, Urbino — 2012.
Implicit intent.
Android looks for the best receiver at
runtime. If it finds:
One, the receiver is activated.
More than one, the user can choose.
None, the intent fails.
71. Android Code Camp, Urbino — 2012.
Implicit intent resolution.
Android decides:
According to the type of component:
Activity, Service, Broadcast Receiver.
According to the field ACTION.
According to the field CATEGORY.
According to the field DATA (URI e Type).
72. Android Code Camp, Urbino — 2012.
Broadcast receiver (reprise).
Intra-application / inter-process
communication.
They receive broadcast intents.
May be associated with other components.
Have no GUI.
May make use of notifications.
May start other components.
73. Android Code Camp, Urbino — 2012.
Broadcast receiver (examples).
Receiving battery status changes.
Being notified of a downloaded file.
Receiving the device boot completed
event.
75. Android Code Camp, Urbino — 2012.
Widget.
Incorporated in other applications (inside
an ―App Widget Host‖).
Long update interval.
(At least: 30 min.)
Receives inputs from the user and updates
from a Broadcast Receiver (which must be
implemented to act as an app widget).
79. Android Code Camp, Urbino — 2012.
Fragment.
Modular part of an activity.
Has its own lifecycle.
Can be added or removed even while the
activity is in resumed state.
Introduced to address the need of putting
an Activity into another.
82. Android Code Camp, Urbino — 2012.
Notification.
Used to notify the user when an event
happened or has been triggered:
In the overall system.
In the activity the user is
interacting with.
In a GUI-less component.
(For instance, a service.)
83. Android Code Camp, Urbino — 2012.
Toast notification.
Suitable for background events.
No user input allowed.
Barely more visible than Logcat…
84. Android Code Camp, Urbino — 2012.
Dialog notification.
Suitable for events relating to the current
activity: loading, confirmation, etc.
Allows (or requires) user input.
85. Android Code Camp, Urbino — 2012.
Status notification.
Suitable for background events.
Requires the user input.
Persistent.
Typically the user has to click on it (or clear
it) to let it disappear from the notifications
bar.
When clicked, usually an
activity is launched.
86. Android Code Camp, Urbino — 2012.
Further details…
More on applications.
Layout.
Back stack.
Activity lifecycle.
Service lifecycle.
Fragment lifecycle.
87. Android Code Camp, Urbino — 2012.
Layout.
Typically composed by
View and ViewGroup (and Fragment).
TableLayout
EditText
TextView
Button
88. Android Code Camp, Urbino — 2012.
Layout.
Generally defined starting from an xml file.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/rss_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
… />
<ListView
android:id="@+id/rss_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
…>
</ListView>
<Button
android:id="@+id/load"
android:layout_width="wrap_content"
… />
</RelativeLayout>
89. Android Code Camp, Urbino — 2012.
Further details…
More on applications.
Layout.
Back stack.
Activity lifecycle.
Service lifecycle.
Fragment lifecycle.
90. Android Code Camp, Urbino — 2012.
Back stack.
Each activity belongs to a task.
Each task contains a collection of activities
ordered by their launch event (back stack).
91. Android Code Camp, Urbino — 2012.
Back stack.
Android handles multiple tasks at the same
time. Only one task can be in foreground
state at
a time.
A new task starts every time an activity has
been lanched from the home screen :
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Some launch modes can affect this.
92. Android Code Camp, Urbino — 2012.
Back stack.
A task structure can be changed by:
• Starting a new activity (increase).
• Using the Back Button (decrease).
The task status changes when:
• There is an interruption for an external event.
• The Home Button is pressed.
• An activity is started from recent menu.
93. Android Code Camp, Urbino — 2012.
Launch modes.
Generally…
• When an activity starts for the first time it
is added on top of the current task (or on
top of a new one if MAIN/LAUNCHER).
• Even if the activity was
already started,
another instance will
be created.
94. Android Code Camp, Urbino — 2012.
Launch modes.
Launch modes allow to define how a new
instance of an activity is associated with
the current task. Launch modes can be
defined via manifest or using intent flags.
Launch Mode Behaviour
Default Creates new activity. Different instances can belong to the same
task. Each task may contain different instances of same activity.
SingleTop Same as Default, but a new instance is started only if the activity
is not at the top of the back stack.
SingleTask If an old instance of the same activity is present in the system
then it will be reactivated, otherwise a new instance is created.
There always be one instance of the same activity in the system.
SingleInstance Same as SingleTask but the activity is always the unique
inhabitant of its task.
96. Android Code Camp, Urbino — 2012.
Further details…
More on applications.
Layout.
Back stack.
Activity lifecycle.
Service lifecycle.
Fragment lifecycle.
104. Android Code Camp, Urbino — 2012.
Activity lifecycle.
Even if the system needs to destroy an
activity in order to get its resources
back, the state should be preserved in
order to maintain the user experience
consistent.
onSaveInstanceState(Bundle)
onRestoreInstanceState(Bundle)
onCreate(Bundle)
105. Android Code Camp, Urbino — 2012.
More on Activity lifecyle.
When will these methods be called?
onRestoreInstanceState() just
after onStart(),
onSaveInstanceState() before
onStop() and maybe before
onPause().
There are no guarantees it will be actually
called (back button)!
106. Android Code Camp, Urbino — 2012.
More on Activity lifecyle.
What should we save in the Bundle?
The transient state of the activity.
The state of the UI (each view saves
its own status).
What shouldn‘t we save in the Bundle?
Data non related to that specific
instance of the activity.
Persistent data should be saved in
the onPause() method.
107. Android Code Camp, Urbino — 2012.
Further details…
More on applications.
Layout.
Back stack.
Activity lifecycle.
Service lifecycle.
Fragment lifecycle.
108. Android Code Camp, Urbino — 2012.
Started & bound services.
Started:
Started by another component
executing the startService()
method.
Killed by itself or by another
component.
109. Android Code Camp, Urbino — 2012.
Started & bound services.
Bound:
Started by 1+ components executing
bindService().
It lasts until the last bound client has
called unbindService().
111. Android Code Camp, Urbino — 2012.
Further details…
More on applications.
Layout.
Back stack.
Activity lifecycle.
Service lifecycle.
Fragment lifecycle.
116. Android Code Camp, Urbino — 2012.
Android Asset Packaging Tool.
Each resource inside /res directory has an
integer ID.
The class R.java is generated:
With a public static final class for
each type of resources.
An integer field named as the
resource it represents.
The R.java is added inside the application
namespace.
117. Android Code Camp, Urbino — 2012.
Resource resolution.
Each resource can has one or more different
versions. Each version is a different folder with a
proper name.
• layout-long
• anim-v14
• drawable-en-rUS-land-night-notouch
English language, in America, in landscape
mode, is night and is not a touch device.
Proper resource is picked at runtime by the
framework.
118. Android Code Camp, Urbino — 2012.
Making resources.
Declaration via XML:
<Button android:id=" @+id/nice_button " />
<string name=―hello_world‖> hello world</string>
Each file should be created in a specific
/res subdirectory.
121. Android Code Camp, Urbino — 2012.
Application manifest.
AndroidManifest.xml in root directory.
Describes the application, its name, its
package, its namespace, its permissions and so
forth.
Declares the minimum and the targeted API
level.
It also describes any components in the
application: activities, services, receivers, etc.
122. Android Code Camp, Urbino — 2012.
Tutorial.
Fancy ways to say „hello world―.
Preparing the work environment.
Creating a new project.
„Hello World― via Logcat.
Layouts, callbacks and toast notifications.
Intents and navigation.
Lists.
Status notifications.
Implementing a background service.
123. Android Code Camp, Urbino — 2012.
Preparing the environment.
Installing the Eclipse IDE.
Adding the Android toolchain (ADT):
https://dl-ssl.google.com/android/eclipse/
Let it download the Android SDK.
…we can start!
124. Android Code Camp, Urbino — 2012.
Tutorial.
Fancy ways to say „hello world―.
Preparing the work environment.
Creating a new project.
„Hello World― via Logcat.
Layouts, callbacks and toast notifications.
Intents and navigation.
Lists.
Status notifications.
Implementing a background service.
126. Android Code Camp, Urbino — 2012.
Tutorial.
Fancy ways to say „hello world―.
Preparing the work environment.
Creating a new project.
„Hello World― via Logcat.
Layouts, callbacks and toast notifications.
Intents and navigation.
Lists.
Status notifications.
Implementing a background service.
127. Android Code Camp, Urbino — 2012.
Android log.
Class android.util.Log.
Different levels of logging:
ASSERT: Log.wtf()
ERROR: Log.e()
WARN: Log.w()
INFO: Log.i()
DEBUG: Log.d()
VERBOSE: Log.v()
128. Android Code Camp, Urbino — 2012.
Android log.
Each log entry has several parameters:
TAG: discriminator (internal to app).
Messaggio: content.
Eccezione: optional.
129. Android Code Camp, Urbino — 2012.
Tutorial.
Fancy ways to say „hello world―.
Preparing the work environment.
Creating a new project.
„Hello World― via Logcat.
Layouts, callbacks and toast notifications.
Intents and navigation.
Lists.
Status notifications.
Implementing a background service.
130. Android Code Camp, Urbino — 2012.
Layouts.
Simple and structured way of developing
the graphical interface of an application.
Flexible and dynamic.
For instance:
LinearLayout,
RelativeLayout,
FrameLayout.
134. Android Code Camp, Urbino — 2012.
Toast notifications.
Created via static method:
Toast.makeText(Context,
“Text”,
Toast.LENGTH_SHORT).show();
Text is shown in an overlay dialog for a
predefined duration.
135. Android Code Camp, Urbino — 2012.
Tutorial.
Fancy ways to say „hello world―.
Preparing the work environment.
Creating a new project.
„Hello World― via Logcat.
Layouts, callbacks and toast notifications.
Intents and navigation.
Lists.
Status notifications.
Implementing a background service.
136. Android Code Camp, Urbino — 2012.
Implicit intent.
Intent i = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
Context.startActivity(i);
The default action ACTION_VIEW is defined
by the system.
It will be handled by the system browser
(by default, since it targets an HTTP
resource).
137. Android Code Camp, Urbino — 2012.
Explicit intent.
Intent i = new Intent(
Context,
Class);
Context.startActivity(i);
Intent targeting an explicit class (an
activity, in this case).
Will not be handled nor resolved at runtime
by the system.
138. Android Code Camp, Urbino — 2012.
Tutorial.
Fancy ways to say „hello world―.
Preparing the work environment.
Creating a new project.
„Hello World― via Logcat.
Layouts, callbacks and toast notifications.
Intents and navigation.
Lists.
Status notifications.
Implementing a background service.
139. Android Code Camp, Urbino — 2012.
Lists.
Lists of data are displayed by a ListView.
Data is handled by a ListAdapter:
It handles access to the data.
Determines how it is shown.
Built in ArrayAdapter works on generic
objects.
140. Android Code Camp, Urbino — 2012.
Custom list adapters.
In order to customize lists:
Adapt data shown for each entry,
Adapt layout,
Adapt colors, formats, headers, etc.
You need to implement a custom
ListAdapter, that overrides
the getView() method.
141. Android Code Camp, Urbino — 2012.
Tutorial.
Fancy ways to say „hello world―.
Preparing the work environment.
Creating a new project.
„Hello World― via Logcat.
Layouts, callbacks and toast notifications.
Intents and navigation.
Lists.
Status notifications.
Implementing a background service.
142. Android Code Camp, Urbino — 2012.
Components of a notification.
Icon (top bar and notification panel).
Ticker text (message in top bar).
Overlay number.
Flags (AUTO_CANCEL, INSISTENT, etc).
Content view (panel),
can be generated (see LatestEvent).
PendingIntent determining action.
Unique Identifier.
143. Android Code Camp, Urbino — 2012.
Updating notifications.
The panel shows one single notification for
each unique notification identifier.
Ensures there is a single notification for
each kind of notification provided by an
application (logical separation).
PendingIntent instances can be updated
by the application (updates the action, not
the notification), and viceversa.
144. Android Code Camp, Urbino — 2012.
Tutorial.
Fancy ways to say „hello world―.
Preparing the work environment.
Creating a new project.
„Hello World― via Logcat.
Layouts, callbacks and toast notifications.
Intents and navigation.
Lists.
Status notifications.
Implementing a background service.
145. Android Code Camp, Urbino — 2012.
Background service.
An Intent is used to explicitly specify a
service to start and to stop.
Intent serviceIntent = new Intent(
Context, Service.class);
Context.startService(serviceIntent);