What is Android?
Android is a software
stack for mobile
devices that includes
an operating system,
middleware and key
applications.
OHA (Open Handset
Alliance)
A business alliance consisting of 47
companies to develop open standards for
mobile devices
ANDROID VERSIONS
ANDROID APIs
API stands for Application Programming Interface,
which as a portion of code, is an interface for
communication among different s/w.
API contains building block joined by programmers.
Application developed for android called Android App.
API level for Android consist of Packages, classes, XML
elements and attributes, intents, set of permissions.
Android KitKat 4.4 supports only level 19 API.
ANDROID ARCHITECTURE
Android S/W Stack - Runtime
Core Libraries
Providing most of the functionality available in the core
libraries of the Java language
APIs
Data Structures
Utilities
File Access
Network Access
Graphics
Etc
Contd.
Dalvik Virtual Machine
Providing environment on which every Android
application runs
Each Android application runs in its own process,
with its own instance of the Dalvik VM.
Dalvik has been written such that a device can run
multiple VMs efficiently.
Register-based virtual machine
Contd
Enabling and simplifying the reuse of
components
Developers have full access to the same
framework APIs used by the core applications.
Users are allowed to replace components.
Contd
Features
Feature
Role
View
System
Used to build an application, including lists, grids, text
boxes, buttons, and embedded web browser
Content
Provider
Enabling applications to access data from other
applications or to share their own data
Resource
Manager
Providing access to non-code resources (localized strings,
graphics, and layout files)
Notification
Manager
Enabling all applications to display customer alerts in the
status bar
Activity
Manager
Managing the lifecycle of applications and providing
a common navigation backstack
Android provides a set of core applications:
Email Client
SMS Program
Calendar
Maps
Browser
Contacts
Etc
All applications are written using the Java language.
Android Application Components
Activities visual user interface focused on
a single thing a user can do
Services no visual interface they run in
the background
Broadcast Receivers receive and react to
broadcast announcements
Content Providers allow data exchange
between applications
Activities
Basic component of most applications
Most applications have several activities that
start each other as needed
Each implemented as a subclass of the base
Activity class
Each activity has a default window to draw in
(although it may prompt for dialogs or
notifications)
The content of the window is a view or a group
of views (derived from View or ViewGroup)
Example of views: buttons, text fields, scroll
bars, menu items, check boxes, etc.
View(Group) made visible via
Services
Does not have a visual interface
Runs in the background indefinitely
Examples
Network Downloads
Playing Music
TCP/UDP Server
You can bind to a an existing service and
control its operation
Broadcast Receivers
Receive and react to broadcast
announcements
Extend the class Broadcast Receiver
Examples of broadcasts:
Low battery, power connected,
shutdown, time zone changed, etc.
Other applications can initiate
broadcasts
Content Providers
Makes some of the application data
available to other applications
Its the only way to transfer data between
applications in Android (no shared files,
shared memory, pipes, etc.)
Extends the class ContentProvider;
Other applications use a ContentResolver
object to access the data provided via a
ContentProvider
Intents
An intent is an Intent object with a message
content.
Activities, services and broadcast receivers are
started by intents. ContentProviders are started
by ContentResolvers:
An activity is started by Context.startActivity(Intent
intent) or Activity.startActivityForResult(Intent intent,
int RequestCode)
A service is started by Context.startService(Intent
service)
An application can initiate a broadcast by using an
Intent in any of Context.sendBroadcast(Intent
intent), Context.sendOrderedBroadcast(), and
Context.sendStickyBroadcast()
Shutting down components
Activities
Can terminate itself via finish();
Can terminate other activities it started via
finishActivity();
Services
Can terminate via stopSelf(); or
Context.stopService();
Content Providers
Are only active when responding to
ContentResolvers
Broadcast Receivers
Are only active when responding to broadcasts
Mapping Application to Process
Demands for Resource allocation, the OS can unload or kill an
application.
System decides which application to be closed on the basis of a
hierarchy or sequence. The system follows rules :
1)
The activities that are visible and Running are given top priority.
2) The second priority is given to activities that are visible and non
running, they have been recently paused and will resume in a
while.
3) Next priority given to running services.
4) Empty
processes are the next candidate for the terminating
processes.
Hardware and Software Tools
Hardware Tools:
Touch screen
GPS
Accelerometer
SD Card
Software Tools:
Internet
Audio and Video support
Contacts
Security
Android application development basics
Android application development on either of the
following operating systems:
Microsoft Windows XP or later version.
Mac OS X 10.5.8 or later version with Intel chip.
Linux including GNU C Library 2.7 or later.
Basic components for application development:
Application Components
Manifest File
Downloading and Installing Android
Android application
development basics
All the required tools to develop Android applications
are freely available and can be downloaded from
the Web.
Java JDK5 or JDK6
Android SDK
Eclipse IDE for Java Developers (optional)
Android Development Tools (ADT) Eclipse Plugin
(optional)
OR
DownloadAndroid Studio.
Download the latest SDK tools and platforms using
theSDK Manager.
Android SDK features
Asoftwaredevelopment kit that enables
developers to createapplicationsfor the
Android platform.
The AndroidSDKincludes sample projects
withsource code, development tools, an
emulator, and required libraries to build
Android applications.
Applications are written using theJava
programming language and run onDalvik, a
customvirtual machinedesigned for
embedded use which runs on top of aLinux
kernel.
Set Up Android Environment
http://developer.android.com/sdk
Install Eclipse
Install Android SDK (Android libraries)
Install ADT plugin (Android development
tools)
Create AVD (Android virtual device)
Create an Android Project in Eclipse
File New Project
Select Android Project
Fill in Project details...
Directory
name
Android
version
Name that appears
on device
Class to
automatically
create
Java package
Run the Android
Application
Run Run (or click the Run button)
Select Android Application
The emulator may take a few minutes to
start, so be patient!
You don't need to restart the emulator
when you have a new version of your
application
Emulator
Source
code
Auto-generated
code
String
constants
onfiguration
UI
layout
HelloAndroid.java
1 public class HelloAndroid extends Activity {
2 /** Called when the activity is first created. */
3
@Override
4 public void onCreate(Bundle savedInstanceState)
5
{
6
super.onCreate(savedInstanceState);
7
setContentView(R.layout.main);
8
}
9 }
main.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello "
/>
</LinearLayout>
strings.xml
1
2
3
4
5
6
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, HelloAndroid!
</string>
<string name="app_name">Hello, Android</string>
</resources>
AndroidManifest.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest
3
xmlns:android="http://schemas.android.com/apk/res/android"
4
package="edu.upenn.cis542"
5
android:versionCode="1"
6
android:versionName="1.0">
7
<application android:icon="@drawable/icon"
8
android:label="@string/app_name">
9
<activity android:name=".HelloAndroid"
10
android:label="@string/app_name">
11
<intent-filter>
12
<action
13
android:name="android.intent.action.MAIN" />
14
<category
15
android:name="android.intent.category.LAUNCHER"/>
16
</intent-filter>
17
</activity>
18
</application>
19 </manifest>