Beruflich Dokumente
Kultur Dokumente
OVERVIEW
Marko Gargenta marakana.com
Agenda
Android
Then
&
Now
Android
versions
The
Stack
Opera<ng
System
Features
Hello
World!
Main
Building
Blocks
Architec<ng
an
App
Android UI Debugging & Logging Android
Security
Summary
Our goal is not just a single device. Our vision is a mobile platform that runs on many many different devices. Eric Schmidt
PlaTorm
Versions
Version
Android
1.0
Android
1.1
Android
1.5
Android
1.6
Android
2.0
Android
2.01
Android
2.1
Android
2.2
Android
2.3
Android
2.3.3
Android
3.x
Android
4.0
1
2
3
4
5
6
7
8
9
10
11,
12,
13
14
API
Level
Android
Android
Cupcake
Donut
clair
clair
clair
FroYo
Gingerbread
Gingerbread
Honeycomb
Ice
Cream
Sandwich
Nickname
Version Distribu<on
Source: Android.com
Historical Distribu<on
Source: Android.com
Add-Ons
SenseUI
TouchWiz
MotoBlur
With Google
Devices that have with Google add-on feature a set of Googles proprietary applications, such as Maps, Gmail, Gtalk, and many others. OEMs and carriers typically enter into a licensing agreement with Google in order to distribute Google version of Android.
ANDROID STACK
The
Stack
Applications
Home Contacts Phone Browser Other
Application Framework
Activity Manager Package Manager Window Manager Telephony Manager Resource Manager Content Providers Location Manager View System Notiication Manager
Libraries
Surface Manager OpenGL
Media Framework
SQLite
Android Runtime
Core Libs
FreeType
WebKit Dalvik VM
SGL
SSL
libc
Linux Kernel
Linux
Kernel
Android Stack
Applications
Phone Browser Other
Linux provides: Hardware abstraction layer Memory management Process management Networking Users never see Linux sub system The adb shell command opens Linux shell
Application Framework
Activity Manager Package Manager Window Manager Telephony Manager Resource Manager Content Providers Location Manager View System Notiication Manager
Libraries
Surface Manager OpenGL
Media Framework
SQLite
Android Runtime
Core Libs
FreeType
WebKit Dalvik VM
SGL
SSL
libc
Linux Kernel
Na<ve
Libraries
Pieces borrowed from other open source projects:
Bionic, a super fast and small license-friendly libc library optimized for Android WebKit library for fast HTML rendering OpenGL for graphics Media codecs offer support for major audio/video codecs SQLite database Much more
Applications
Home Contacts Phone Browser Other
Application Framework
Activity Manager Package Manager Window Manager Telephony Manager Resource Manager Content Providers Location Manager View System Notiication Manager
Libraries
Surface Manager OpenGL
Media Framework
SQLite
Android Runtime
Core Libs
FreeType
WebKit Dalvik VM
SGL
SSL
libc
Linux Kernel
Dalvik
Dalvik VM is Android implementation of Java VM Dalvik is optimized for mobile devices: Battery consumption CPU capabilities Key Dalvik differences: Register-based versus stack-based VM Dalvik runs .dex files More efficient and compact implementation Different set of Java libraries than JDK
Applica<on
Framework
Applications
The rich set of system services wrapped in an intuitive Java API. This ecosystem that developers can easily tap into is what makes writing apps for Android easy. Location, web, telephony, WiFi, Bluetooth, notifications, media, camera, just to name a few.
Home
Contacts
Phone
Browser
Other
Application Framework
Activity Manager Package Manager Window Manager Telephony Manager Resource Manager Content Providers Location Manager View System Notiication Manager
Libraries
Surface Manager OpenGL
Media Framework
SQLite
Android Runtime
Core Libs
FreeType
WebKit Dalvik VM
SGL
SSL
libc
Linux Kernel
Applica<ons
Dalvik Executable + Resources = APK Must be signed (but debug key is okay for development) Many markets with different policies
App
Distribu<on
One
of
the
markets
Side
loading
Internal
app
directory
Markets
Google
Android
Market
Amazon
Android
Market
Other
emerging
markets
Side Loading
Mul<media
AudioPlayer lets you simply specify the audio resource and play it. VideoView is a View that you can drop anywhere in your activity, point to a video file and play it. XML: <VideoView android:id="@+id/video" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center /> Java: player = (VideoView) findViewById(R.id.video); player.setVideoPath("/sdcard/samplevideo.3gp"); player.start();
Video Image
RTSP and HTTP progressive streaming. HTTP live streaming coming soon. More native support in the works. Native support available via Khronos OpenMax IL
Big deal for many pull-based apps. Will make devices use less battery.
Device
Administra<on
New in FroYo: Android Device Admin API. Administrator can set: Enable passwords Set password quality Max failed logins Prompt for new password Remotely wipe device data Lock the device App requests Device Admin permissions. If granted, admin policies apply. If not, app doesnt work. Policies could be hard-coded or dynamic. Third-party enterprise solutions use this framework to build DM policies.
File
System
The file system has three main mount points. One for system, one for the apps, and one for whatever. Each app has its own sandbox easily accessible to it. No one else can access its data. The sandbox is in /data/data/com.marakana.yamba/ SDCard is expected to always be there. Its a good place for large files, such as movies and music. Everyone can access it. System partition is where the entire Android operating system is, customized by OEM or not.
HELLO WORLD!
Anatomy
of
An
App
Java Code + XML and Other Resources + Manifest File = Android App
Running on Emulator
Yamba Demo
Lets see a real-world medium complexity Android app in action: Yamba: Yet Another Micro Blogging App
Ac<vi<es
An Activity represents a screen or a window. Sort of.
Android Application
Main Activity Another Activity Another Activity
Ac<vity
Lifecycle
Activities have a welldefined lifecycle. The Android OS manages your activity by changing its state. You fill in the blanks.
Intents
Intents represent events or actions. They are to Android apps what hyperlinks are to websites. Sort of. Intents can be implicit or explicit.
Services
Services are code that runs in the background. They can be started and stopped. Services doesnt have UI.
Service
Lifecycle
Service also has a lifecycle, but its much simpler than activitys. An activity typically starts and stops a service to do some work for it in the background, such as play music, check for new tweets, etc. Services can be bound or unbound.
Remote Services
Content
Providers
Content Providers share content with applications across application boundaries. Examples of built-in Content Providers are: Contacts, MediaStore, Settings and more.
Broadcast Receivers
An Intent-based publish-subscribe mechanism. Great for listening system events such as SMS messages.
Architecture
of
An
App
An Android application is a collection of many different building blocks. They are loosely coupled and can be reconfigured by the developer easily, or at least thats the intention. Lets look at 7 stages of Yamba next.
Yamba Part 1
Yamba Part 2
Yamba Part 3
Yamba Part 4
Yamba Part 5
Yamba Part 6
Yamba Part 7
Two
UI
Approaches
Procedural
You
write
Java
code
Similar
to
Swing
or
AWT
DeclaraKve
You
write
XML
code
Similar
to
HTML
of
a
web
page
You can mix and match both styles. Best practice: Start with XML and declare most of UI Switch to Java and implement the UI logic
Use WYSIWYG tools to build powerful XML-based UI. Easily customize it from Java. Separate concerns.
Linear
Layout
One of the most commonly used layouts. It lays its children next to each other, either horizontally or vertically.
Rela<ve
Layout
Children of relative layout are placed in relationship to each other. This layout is efficient.
Table
Layout
Table layout puts its children into table rows and columns. It is similar to an HTML table.
Frame
Layout
Frame layout places its children on top of each other, like a deck of cards. It is useful for widgets such as tabs or as a placeholder for views added programmatically.
Common
UI
Components
Android UI includes many common modern UI widgets, such as Buttons, Tabs, Progress Bars, Date and Time Pickers, etc.
Selec<on
Components
Some UI widgets may be linked to zillion pieces of data. Examples are ListView and Spinners (pull-downs).
Adapters
Adapter
Data Source
To make sure they run smoothly, Android uses Adapters to connect them to their data sources. A typical data source is an Array or a Database.
Complex
Components
Certain high-level components are simply available just like Views. Adding a Map or a Video to your application is almost like adding a Button or a piece of text.
Mul<media
AudioPlayer lets you simply specify the audio resource and play it. VideoView is a View that you can drop anywhere in your activity, point to a video file and play it. XML: <VideoView android:id="@+id/video" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center /> Java: player = (VideoView) findViewById(R.id.video); player.setVideoPath("/sdcard/samplevideo.3gp"); player.start();
LogCat
The universal, most versatile way to track what is going on in your app. Can be viewed via command line or Eclipse. Logs can be generated both from SDK Java code, or low-level C code via Bionic libc extension.
Debugger
Your standard debugger is included in SDK, with all the usual bells & whistles.
TraceView
TraceView helps you profile you application and find bottlenecks. It shows execution of various calls through the entire stack. You can zoom into specific calls.
Hierarchy
Viewer
Hierarchy Viewer helps you analyze your User Interface. Base UI tends to be the most expensive part of your application, this tool is very useful.
ANDROID SECURITY
Security
Overview
No app can adversely impact other apps, user, or OS Cannot read/write users private data Cannot read other apps data Cannot perform network access Cannot keep device awake, and so on Each application is its own sandbox To share resources, apps need to request permissions User must grant permissions at install time Linux manages security Not up to Dalvik (Java) but outsourced to Linux Native code (NDK) also adheres to sandboxing
Applica<on
Sandboxing
An application is an island on its own. It contains any number of Activities, Services, Receivers and Providers. It has its own file system, database, place to store native libraries. No other app can access any of its data without prior permission.
Permissions
A component that does something potentially dangerous can require callers to have permission to access it. App that wants to use it must have user grant it permission. Permissions are granted at install time. All or nothing. Forever.
Summary
Android is open and complete system for mobile development. It is based on Java and augmented with XML. It takes about 3-5 days of intensive training to learn Android application development for someone who has basic Java (or similar) experience.