Transcript
Department of Computer Science Institute for System Architecture, Chair for Computer Networks
Application Development for Mobile and Ubiquitous Computing 9. Platforms Android, iOS and WP7 Dr. Ing. Thomas Springer Technische Universität Dresden Chair of Computer Networks
Lecture Structure Application Development Cross-Platform Development
Java ME
Android
iOS
Adaptation and Contextawareness
.Net Compact Framework/ Windows Phone 7
OSGi
Mobile Middleware
Disconnected Operations
Mobile Databases
Locationbased Services
Communication Mechanisms
Mobile Internet
Enabling Technologies and Challenges
Dr. Thomas Springer
Application Development - 9. Platforms
Slide 2
Structure
Java ME OSGi
Android iOS Windows Phone 7
Dr. Thomas Springer
Application Development - 9. Platforms
3
Reviewing Java ME
Mobile Device
Midlet Suite
Midlet Suite
...
Optional Packets MIDP Profile CLDC Configuration, KVM
Operating System
Hardware
Dr. Thomas Springer
Created by: Sun Microsystems, acquired by Oracle Corporation in 2010 Target devices: cellular phones, PDAs, embedded devices Operating System: any system Approach: open source, no hardware restrictions Programming: Java Development: any hardware Development tools: various IDEs and development kits App Provisioning: Over the air provisioning by vendor Developer Program: free
Application Development - 9. Platforms
4
ANDROID
Android Overview
Created by: Open Handset Alliance, driven by Google, First Release: Android 1.0 beta in November 2007 Target devices: smartphones and tablets from different vendors Operating System: Linux Kernel Approach: open source (Apache 2.0 license, some libs excluded (e.g. Google Maps), heterogeneous hardware Programming: Java Development: any hardware Development tools: Eclipse Plugin + Android SDK App Provisioning: Android market maintained by Google, additional markets (AndroidPit, …) Developer Program:
Dr. Thomas Springer
Application Development - 9. Platforms
6
Android Architecture
Application Framework allows reuse and exchange of components Libraries •
•
• • •
Media Libraries supporting many popular formats, (MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG) SQLite - lightweight relational database engine Google Maps support Integrated Browser based on WebKit Optimized graphics libraries (2D library, 3D library based on OpenGL
Mobile Device
App .apk
App .apk Application Framework
Libraries
Special VM (Dalvik VM) Linux Kernel (based on version 2.6) • • • •
threading low-level memory management hardware drivers power management
Dr. Thomas Springer
...
Application Development - 9. Platforms
Dalvik VM + Core libraries
Linux Kernel
Hardware
7
Dalvik Virtual Machine
Alternative Java runtime implementation • no Sun/Oracle certification • basically just the syntax of the progr. language is the same • Dalvik byte code o must be compiled for Dalvik VM • no full Java ME, no full Java SE o four major libraries 'lang', 'util', 'io', 'net' fully available • Cross-compiler for Java standard bytecode
Optimized for mobile computers • memory management • every application runs in its own process • optimized for many parallel VMs Dr. Thomas Springer
Application Development - 9. Platforms
8
Anatomy of an Android application
Four building blocks • Activities, Broadcast Intent Receiver, Services, Content Providers
Android Apps run in separate processes Inter-process communication based on AIDL interfaces Used components have to be declared in the Android Manifest file Activity A
intent
Activity B
service Binder broadcast intent
Dr. Thomas Springer
Local Service
Inter-process communication AIDL
Remote Service
Dalvik VM
Dalvik VM
Process
Process Application Development - 9. Platforms
9
Building Blocks - Activities
Activity: • • • • •
a single screen of the application extends the Activity class consists of user interface elements (views) that respond to events may return a value to another activity When a new screen opens, the previous is put onto a history stack. • methods of activity reflect lifecycle
onCreate initialized
onStart
removed
onResume visible
onRestart
active onPause
onStop onDestroy
Dr. Thomas Springer
inactive
Application Development - 9. Platforms
10
Building Blocks - Services Service: • • • •
background thread working independent from the UI Local and Remote Services Activities can connect through bindService() When connected, communication is done by an interface exposed by the service; the interface is based on the AIDL (Android Interface Definition Language). onCreate initialized removed onStart
onDestroy
Dr. Thomas Springer
running
Application Development - 9. Platforms
11
Building Blocks - Intents
Intent:
BroadcastReceiver:
• Events/messages exchanged between Activities at application level • "message objects" used to move from one activity to another • Consists of an Action string, URI and payload • Common action values are MAIN (to open an app), VIEW, PICK and EDIT • Example: "VIEW" with web address opens the browser, "CALL" calls a provided number • Intent Filter express ability of component to handle particular intent types
• Broadcast intents represent events propagated by the system (e.g. battery low, screen off, boot completed) • BroadcastReceiver is special intent filter for system messages
Dr. Thomas Springer
Application Development - 9. Platforms
12
Android Manifest
AndroidManifest.xml necessary for every application Describes the application‘s elements and when they should be initialized or activated Includes a list of permissions the application is offering or needing (e.g. for access to network or contacts data); so on installation, the user can grant or deny these.
Dr. Thomas Springer
Application Development - 9. Platforms
13
Android UI Creation
UI is based on Screens Activities create and control screens (one activity per screen) • contain application logic, layout and views
Views as visible elements of UI • Base class android.view.View
Layouts arrange views on screen • Base class android.view.ViewGroup, (i.e. layout is group of views)
Dr. Thomas Springer
Application Development - 9. Platforms
14
Android UI Creation
XML-based description of UIs Alternatively UI creation in code Support of touch-based interactions Event-mechanism to handle interactions •
E.g. view.setOnClickListener(callback)
Dr. Thomas Springer
Application Development - 9. Platforms
15
Android Network Communication
Java.net.* APIs can be used Alternatively HttpComponents library (Jakarta Commons) • Provided as part of Android platform • Base for HTTP conections is HTTPClient
Android.net.ConnectivityManager • Monitors connectivity state • Sends broadcast intent if connection state changes • Provides methods for accessing network state o getActiveNetworkInfo() o getAllNetworkInfo() o getNetworkInfo(int networkType)
Dr. Thomas Springer
Application Development - 9. Platforms
16
Android Persistent Storage SQLite • • • •
Local data base with SQL and transaction support Data base maintained in single file Base class android.database.sqlite.SQLiteDatabase execute SQLite queries using the SQLiteDatabase query() methods
Shared Preferences • Base class android.content.SharedPreferences • Store private primitive data in key-value pairs
Internal Storage • Store private data on the device memory as files.
External Storage • Store public data on the shared external storage as files.
Dr. Thomas Springer
Application Development - 9. Platforms
17
Android Persistent Storage
ContentProvider: • Sharing of data between applications o Abstraction layer on top of DB or files (interface android.content.ContentProvider) o Content organized like on web server – content URIs for access -
e.g. content://de.tudrn.exampleprovider/images/content_id
o Implement a standard set of methods for allowing other applications to store and retrieve data. o ContentProvider implementation for common data types o Access via ContentResolvers Content Consumer
Content Resolver
getContentResolver()
query() insert() update() delete()
ContentProvider query() insert() update() delete()
openFile() ...
openInputStream(Uri, ...) openOutputStream(Uri,…)
data source (DB)
Dr. Thomas Springer
Application Development - 9. Platforms
data source (files)
18
Android Development Tools
Eclipse plugin + Android SDK • Project management • Device emulator • Debugger
Dr. Thomas Springer
Application Development - 9. Platforms
19
Android App Provisioning
Google provides the Android market Development is free Transaction fee for selling applications in the android market • 30% of the application price. For example, if you sell your application at a price of $10.00, the fee will be $3.00, and you will receive $7.00 in payment.
Alternative markets allowed • E.g. AndroidPit • at http://www.androidpit.de
Dr. Thomas Springer
Application Development - 9. Platforms
20
IOS
iOS Overview
iOS (formerly iPhone OS) Created by: Apple Inc. First Release: June 2007 Target devices: iPhone, iPad, iPod touch, Apple TV Operating System: based on Mach/BSD Kernel Approach: closed source, restricted hardware Programming: Objective-C, C, (C++) Development: Apple Hardware: “Develop for Mac on a Mac” Development tools: Xcode + iOS SDK App Provisioning: App Store maintained by Apple Developer Program: Company $299/year, Individual $99/year
Dr. Thomas Springer
Application Development - 9. Platforms
22
Apple Hardware Apple iPad UMTS, GSM, Wi-Fi, BT
A-GPS, Accelerometer, light sensor, Camera Display 1024 x 768 px
Apple iPhone 4S UMTS, GSM, Wi-Fi, BT A-GPS, Compass Accelerometer, Gyro, Light Sensor Display 960 x 640 px 1st Camera @ 5 MP [Apple Inc.] Dr. Thomas Springer
2nd Front Camera Application Development - 9. Platforms
23
Objective-C
Created in the early 80s by Stepstone Extends C with object-oriented constructs • Extensions based on Smalltalk • Objective-C code can be mixed with C-code
Objective-C vs. Java • Separate files for interface (header - .h) and implementation (.m) of classes • No namespaces/packages • Messages to invoke methods • Pointer syntax • No method overloading (same method name/different parameter type) • No garbage collection (iOS), explicit memory management required (supported by compiler)
Dr. Thomas Springer
Application Development - 9. Platforms
24
iOS Architecture Mobile Device
App .ipa
App .ipa
...
Cocoa Touch: Objective-C APIs for lower layers, e.g., multi touch, camera, web view, accelerometer,... That’s what you use mostly!
Custom Frameworks Cocoa Touch
UIKit
For performance optimisation
Media
Core Services
Foundation
Mach/BSD Kernel
Hardware
Media: OpenGL ES, Core Audio, OpenAL, PDF, PNG, JPG, TIFF, Quartz 2D
Core Services: Address book, SQL lite, network, location services, threading, NS Object Core OS: OS X Kernel, BSD, Mach 3.0, file system, power management, security Limited access for developers
Dr. Thomas Springer
Application Development - 9. Platforms
25
iOS Application Anatomy Cocoa Touch Frameworks in iOS: • Foundation (NS… prefix) o Data types and structures Strings, Array, Maps,... o Services & functionality (Date, Calendar, Timer,...)
• UIKit o UI related objects (“views”), pretty new
Based on design patterns: • Model-View-Controller – defines the overall app structure • Delegation - facilitates the transfer of information and data from one object to another • Target-action - translates user interactions with buttons and controls into code that your app can execute.
Dr. Thomas Springer
Application Development - 9. Platforms
26
Model View Controller Controller
user action
View
update
update
notify
Model
no direct interaction between View and Model
Model • Encapsulate data and basic behaviour • Stores application data (persistently)
View • Present information to user • Allow users to edit model data
Controller • Mediates access of views to models • Contains busines logic for processing user input • Set-up and coordination tasks
Dr. Thomas Springer
Application Development - 9. Platforms
27
Delegate Design Pattern
Protocols • Similar to interfaces in Java • Define methods that are to be implemented by other class
Delegation = mechanism for customization and notification • delegation over subclassing • Advantages o easier switch at runtime (exchange delegate object vs. instantiation of a different view class) o Views are completely reusable
• View holds reference to controller (defined as Outlet) • Controller implements methods of delegate-protocol • View invokes methods on its delegate object (controller)
Controller should... will...
View dele
should... will...
Dr. Thomas Springer
did...
gate
did...
Application Development - 9. Platforms
28
Target-Action Design Pattern
Target-Action – mechanism for notification • Actions represent events created by users interacting with the UI (e.g. button pressed) • Controller implements action handling o Defined by (IBAction)actionName
• View dynamically invokes methods when actions happen • No return values (IBAction compiles to void)
Controller target
View action
Dr. Thomas Springer
Application Development - 9. Platforms
29
iOS Application Anatomy UIApplication
ApplicationDelegate
(Singleton)
didFinishedLaunching {
holds reference to delegate 1
init ViewController
id .delegate
}
2
UIViewController
UIViewController 3
UIView defined in .xib or directly created in code
.view
One Screen per ViewController Similar to Android Activities
UIView
ContainerViewController can control several ViewController (e.g. NavigationViewController)
defined in .xib or directly created in code
.view
set to UIWindow
Dr. Thomas Springer
Application Development - 9. Platforms
30
iOS Multitasking
Before iOS 4, multitasking was limited to a selection of the applications Apple included on the devices. Starting with iOS 4, on 3rd-generation and newer iOS devices, multitasking is supported through seven background APIs: • Background audio - application continues to run in the background as long as it is playing audio or video content • Voice over IP - application is suspended when a phone call is not in progress • Background location - application is notified of location changes • Push notifications • Local notifications - application schedules local notifications to be delivered at a predetermined time • Task completion - application asks the system for extra time to complete a given task • Fast app switching - application does not execute any code and may be removed from memory at any time
Threads are supported based on the NSThread class
Dr. Thomas Springer
Application Development - 9. Platforms
31
iOS UI Creation
Based on Interface Builder • • • •
.xib files for describing view hierarchies (.nib is binary form) One .xib describes typically one screen Created/Edited with Interface Builder No direct manipulation of .xib/xml
UIKit class library provides set of predefined Views, ViewControllers and Controls
Dr. Thomas Springer
Application Development - 9. Platforms
32
Tools for iOS Development: Interface Builder Visual editor • Assembling UI • Nib-file generation
Inspectors for • Identity • Size, position and layout • Attributes • Connections
Dr. Thomas Springer
Application Development - 9. Platforms
33
iOS Libraries
Root Class: NSObject (defined in foundation lib)
UIApplication
NSObject NSNumber
UIViewController
NSArray
UIView NSString UIControl UIButton
NSDate NSSet
NSURL
NSDictonary foundation library
UIKit library
Dr. Thomas Springer
Application Development - 9. Platforms
34
iOS Network Communication Part of foundation library • NSURLConnection, NSURLRequest, NSURLMutableRequest
Dr. Thomas Springer
Application Development - 9. Platforms
35
iOS Communication Important connection-related protocols: • NSURLConnectionDelegate o Catch errors: o connection:didFailWithError:
• NSURLConnectionDataDelegate o connection:didReceiveResponse: o connection:didReceiveData: o connectionDidFinishLoading:
Alternative: AFNetworking library o 3rd party library o Provides convenient abstractions for request creation, response parsing, error handling
Dr. Thomas Springer
Application Development - 9. Platforms
36
iOS Persistent Storage
Key-Value Storage • • • •
NSUserDefaults (simple Hash synchronized with file) Singleton Automatically synchronized by system stored in App sandbox
Framework Core Data • Runtime Objects synchronized with SQLite • Abstraction layer for objects • Core data objects are mapped to relational DB
SQLite Files in Sandbox iCloud • Key-Value Storage (Hash) with automatic synchronization to iCloud • Data objects derived from UIDocument, can easily be synchronized with iCloud
Dr. Thomas Springer
Application Development - 9. Platforms
37
Tools for iOS Development Overview
[Apple, Inc.] Dr. Thomas Springer
Application Development - 9. Platforms
38
iOS Development Tools: XCode
IDE for Mac and iOS development
Manage projects Code editing Building (on device & simulator) Debugging (on device & simulator) Repository management Performance tuning
Dr. Thomas Springer
Application Development - 9. Platforms
39
Tools for iOS Development Instruments • Performance analysis tool (incl. graphical display) o o o o
Memory usage Disk activity Network activity Graphics performance
Dr. Thomas Springer
Application Development - 9. Platforms
40
Tools for iOS Development iOS Simulator • Simulator for iPhone / Retina & iPad o Choice of iOS versions
Dr. Thomas Springer
Application Development - 9. Platforms
41
iOS Developer Program o Company ($299/year) o Individual ($99/year) o Limited to 100 devices
Dr. Thomas Springer
Application Development - 9. Platforms
42
WINDOWS PHONE 7
WP7 Overview
Windows Phone 7 Created by: Microsoft First Release: September 2010 Target devices: Smartphones Operating System: based on Win CE 7 Approach: closed source, restricted hardware Programming: C# Development: any hardware, Windows Development tools: Microsoft Visual Studio 2010 App Provisioning: App Marketplace maintained by Microsoft Developer Program: 99$ per year, free for students
Dr. Thomas Springer
Application Development - 9. Platforms
44
WP7 Supported Hardware
Hardware from multiple vendors supported But strict resource specifications • Resolution o 480x800 or 320x480
• Touch screen • Sensors & Services o GPS, Compass, Acceleration Sensor, Light Sensor, WLAN, FM Radio, Camera
• Memory o At least 256 MB RAM, 8GB Flash
• CPU (ARMv7) o At least 1 GHz
• Set of Keys o Power, volume, camera, back, start, search Dr. Thomas Springer
Application Development - 9. Platforms
45
WP7 Architecture
Mobile Device
App .xap
App .xap
XNA
• Several frameworks for UI • All based on CLR
...
HTML/JavaScript
UI Model
Cloud Integration
Cloud Integration • Bing, Location, Push notifications, …
Kernel Hardware Foundation
UI Model • Shell frame, session manager, Direct3D, compositor
Common Language Runtime App Model
App Model • App management, licensing, updates
Frameworks Silverlight
Applications
Kernel • Security, Networking, Storage, Sensor integration
Hardware
Dr. Thomas Springer
Hardware foundation
Application Development - 9. Platforms
46
WP7 App Model
App provided as bundle – XAP file (ZIP archive) • • • • •
DDL with code Resources (images, app icon, etc.) Manifest for App description No exe, App is executed by host process Host process provices sandbox o o o o
Dr. Thomas Springer
Separates Apps Restricts access to device resources Manages own files Manages system resources for App
Application Development - 9. Platforms
47
WP7 App Anatomy
Apps are based on the .Net Compact framework
Mobile version of .Net Framework
Specific runtime environment
Based on Common Language Infrastructure (CLI)
Particular layer for device platform and operating system independence
• Adapted compared to Windows Mobile • UI Model changed completely for WP7
• tailored to resource limitations of mobile devices • same programming model
• adapted to limited memory, processing power and portability
• standard for programming language and platform-independent applications • binary compatible with standard .Net framework code • supported languages: C# and Visual Basic .Net • open to further languages which can be compiled to CLI-code
Dr. Thomas Springer
Application Development - 9. Platforms
48
.Net Compact Framework Building Blocks
2 major building blocks • Compact Framework Class Libraries (Common Language Intermediary) o object-oriented libraries organized in hierarchical name space o provides basic functionality and interfaces for XML processing, Web services, and for developing web-based applications o language independent, factored into a series of DLL files o only used libraries are integrated
• Common Language Runtime (CLR) o comparable with Java VM – runtime executes intermediary byte code o memory management, thread management, security model, exception handling o Common Type System -
Dr. Thomas Springer
language-independent type system enables interoperability of different programming languages and platforms
Application Development - 9. Platforms
49
.Net Compact Framework Architecture
App 1
App 2
App 3
.Net Compact Framework
Compact Framework Class Libraries Common Language Runtime (CLR)
User Interface
Web Services
XML
Base Classes
Execution Engine
Data
Managed Code Native Code
Platform Adaptation Layer
Host Operating System
Dr. Thomas Springer
Application Development - 9. Platforms
50
.Net Compact Framework Runtime Environment Common Language Runtime • executed with all applications in one process –usage of shared memory space • managed code isolated in application domains • JIT compiler o transfers code to memory o transformation to native code – at granularity of methods and types o only used code blocks are transformed and cached o Two compiler versions - IJIT – fast, generated generic code - SJIT – optimized for ARM processors
• garbage collector o based on Mark-and-Sweep algorithm o Defragmentation
Dr. Thomas Springer
Application Development - 9. Platforms
51
.Net Compact Framework Native Code (not available in WP7)
• provided in target processor native code • Execution Environment
o Just-in-Time Compiler transforms CLI-code to processor specific code
• Platform Adaptation Layer
o enables independence from particular OS o maps OS APIs to .Net Compact Framework APIs
• Operating System
o .Net Compact Framework independent from Windows
Managed Code
• provided as language independent byte code • transformed to native code by Just-in-time compiler at runtime • Applications • Extension Libraries • Class Libraries
Dr. Thomas Springer
Application Development - 9. Platforms
52
Base Class Libraries
comprise • core types, file I/O, sockets networking • reflection • globalization – localization supported • • • • • • •
System.*, System.Collections.* System.ComponentModel.* System.IO.* System.Net.Sockets.* System.Security.* System.Threading.* …
Dr. Thomas Springer
Application Development - 9. Platforms
53
Network, Web Services and XML
Multiple Protocol support
Web Services well supported
• • • •
System.Net.Sockets class abstracts from transport protocols TCP, UDP and HTTP supported Standard mechanisms for encryption and authentication Handling of IP-Addresses
• based on Visual Studio .Net features
o parses WSDL documents o generates easy-to-use client proxy classes o System.Net.*
XML processing
• simple XML processing – XmlReader, XmlWriter • maximum performance, noncached, forward only XML reading and writing • XML DOM – XmlDocument class • in-memory tree for more complex operations on document • System.Xml.*
Dr. Thomas Springer
Application Development - 9. Platforms
54
Persistent Memory
File Access using System.IO.* classes and operations Active Data Objects (ADO.Net) • classes for management of relational data sets • DataSets in memory can be manipulated • DataAdapters allow access two different types of data sources
Microsoft SQL Server CE • • • • •
lightweight version of SQL Server for mobile devices uses 1MB up to 3MB memory SQL Server in backend as master DB Data replicated on lightweigth DB ActiveSync component coordinates synchronization
Dr. Thomas Springer
Application Development - 9. Platforms
55
WP7 UI Creation
Completely changed in WP7 • Silverlight • XNA Framework • HTML/JavaScript
Metro design • Originated in Windows Media Center and Zune • Inspired by public transport signs • Objectives o o o o
Clean, Light, Open, Fast Content, not Crome Integrated hardware and software (integration of phone keys) Soulful and Alive (personalized, continuously updated)
• Style guides for UI design
Dr. Thomas Springer
Application Development - 9. Platforms
56
WP7 UI Creation
UI Model • Based on Silverlight 3 • Subset of „Classical Silverlight“
Frame contains several pages for App
Frame 1-n Page(s)
• Web-like navigation • All viewed pages on stack (from multiple apps) • User can navigate back and forth Content Area
Dr. Thomas Springer
Application Development - 9. Platforms
57
Development Environment
Visual Studio 2010 Express for Windows Phone Dr. Thomas Springer
Application Development - 9. Platforms
58
Platform Comparision Vendor Current Version Device hardware
Android Google Inc. 4.0 (Ice Cream Sandwich) not restricted, various vendors (smartphones, tablets)
iOS Apple Inc. 5.0
WP7 Microsoft 7.10
Restricted to Apple devices (iPod, iPhone, iPad, Apple TV)
Various vendors, strictly defined hardware requirements
OS App runtime
Linux Kernel Dalvik VM
Mach/BSD Kernel Native code on Mach/BSD Kernel Objective-C, C (C++)
Win CE 7 Common Language Runtime C#
NO
NO
Apple Hardware and OS required Company $299/year, Individual $99/year
Any hardware, Windows 99$ per year, free for students
Programming Java Language Open source YES (Apache 2.0 license, some libs excluded, e.g. Google Maps) Development Any hardware and OS restrictions Developer development free program Dr. Thomas Springer
Application Development - 9. Platforms
59
References
Android • Arno Becker, Markus Pant: Android 2 – Grundlagen und Programmierung. Dpunkt Verlag, 2. aktualisierte Auflage, 2010 • http://developer.android.com • http://code.google.com/android
iOS • Cocoa fundamentals: http://developer.apple.com/library/mac/ #documentation/cocoa/conceptual/CocoaFundamentals/CocoaD esignPatterns/CocoaDesignPatterns.html • Bill Dudney, Chris Adamson: Entwickeln mit dem iPhone SDK. Oreilly, 2010
Windows Phone 7 • msdn.microsoft.com/de-de/library/cc656764.aspx • Ivo Salmre: Writing Mobile Code-Essential Software Engineering for Building Mobile Applications, Addison-Wesley, 2005 • Patrick Getzmann, Simon Hackfort, Peter Nowak: Entwickeln für Windows Phone 7 – Architektur, Frameworks, APIs, Microsoft Press, 2011
Dr. Thomas Springer
Application Development - 9. Platforms
60