Preview only show first 10 pages with watermark. For full document please download

Application Development For Mobile And Ubiquitous Computing 10

   EMBED


Share

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 Mobile Business Apps Cross-Platform Development Adaptation and Contextawareness Mobile Web Apps Android iOS .Net Compact Framework/ Windows Phone 7 Java ME Mobile Middleware Disconnected Operations Mobile Databases Locationbased Services Communication Mechanisms Mobile Internet Enabling Technologies and Challenges Dr. Thomas Springer Application Development -7. Communication Mechanisms Slide 2 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 3 ANDROID Android Overview  Created by: Open Handset Alliance, driven by Google  First Release: Android 1.0 beta in November 2007  Current version: 4.2 (Jelly Bean)  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 Dr. Thomas Springer Application Development - 9. Platforms 5 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 6 Dalvik Virtual Machine  Alternative Java runtime implementation • no Sun/Oracle certification • basically just the syntax of the programming 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 7 Anatomy of an Android application  Four building blocks • Activities, Services, Content Providers, BroadcastReceiver    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 8 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 9 Building Blocks - Services  Service: • Means for • Performing tasks in background (startService) • Expose functionality to other apps (bindService) • Creation of new Thread in onCreate() method • Local and Remote Services • When connected, communication is done by an interface exposed by the service; the interface is either based on Java (local) or based on AIDL (Android Interface Definition Language) for access from other processes (remote). 10 Building Blocks - Intents  Intent: • passive data structure holding an abstract description of an operation to be performed • Used to o start Activity or Service o broadcast to any interested BroadcastReceiver • consists of an action and data (+further data) o ACTION_VIEW content://contacts/people/1 -- Display information about the person whose identifier is "1". o ACTION_DIAL tel:123 -- Display the phone dialer with the given number filled in. • Intent Filter express ability of component to handle particular intent types  BroadcastReceiver: • 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 11 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 12 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 13 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 14 Android Network Communication  Java.net.* APIs can be used • Provided as part of Android platform • Base for HTTP conections is HTTPClient  Alternative libraries can be used • e.g. Apache HttpComponents project  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 15 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 16 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) 17 Android Development Tools  Eclipse plugin + Android SDK • Project management • Device emulator • Debugger Dr. Thomas Springer Application Development - 9. Platforms 18 Android App Provisioning  Google Play Store for app provisioning  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. Dr. Thomas Springer Application Development - 9. Platforms 19 IOS iOS Overview           iOS (formerly iPhone OS) Created by: Apple Inc. First Release: June 2007 Current Version: iOS 6.0.1 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 Dr. Thomas Springer Application Development - 9. Platforms 21 Apple Hardware Apple iPad UMTS, LTE, GSM, Wi-Fi, BT A-GPS, Accelerometer, light sensor, Camera Display 1024 x 768 px / 2048 x 1536 px Apple iPhone 5 UMTS, LTE, GSM, Wi-Fi, BT A-GPS, Compass Accelerometer, Gyro, Light Sensor Display 1136 x 640 px 1st Camera @ 8 MP [Apple Inc.] Dr. Thomas Springer 2nd Front Camera Application Development - 9. Platforms 22 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 for explicit handling of pointers • 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 23 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 24 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”)  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 25 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 26 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 27 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 28 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 29 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 31 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 32 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 33 iOS Network Communication  Part of foundation library • NSURLConnection, NSURLRequest, NSURLMutableRequest Dr. Thomas Springer Application Development - 9. Platforms 34 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 36 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 38 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 39 Tools for iOS Development iOS Simulator • Simulator for iPhone / Retina & iPad o Choice of iOS versions Dr. Thomas Springer Application Development - 9. Platforms 40 iOS Developer Program o Company ($299/year) o Individual ($99/year) o Limited to 100 devices Dr. Thomas Springer Application Development - 9. Platforms 41 WINDOWS PHONE Windows Phone Overview      Windows Phone 7/8 Created by: Microsoft First Release: September 2010 Target devices: Smartphones Operating System: • based on Win CE 7 (WP7) • Windows NT (WP8)     Approach: closed source, restricted hardware Programming: C# Development: any hardware, Windows Development tools: Microsoft Visual Studio 2012 Dr. Thomas Springer Application Development - 9. Platforms 43 Windows Phone Supported Hardware  Hardware from multiple vendors supported  But strict resource specifications • Resolution o 1280x720, 800x480, 480x320 • 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 44 Windows Phone 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 45 Windows Phone 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 provides 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 46 Windows Phone 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 Windows Phone • 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 47 .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 48 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 53 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 54 Windows Phone UI Creation  Completely changed in WP • 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 55 Windows Phone 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 56 Development Environment Visual Studio 2012/Visual Studio Express 2012 for Windows Phone Dr. Thomas Springer Application Development - 9. Platforms 57 Platform Comparision Vendor Current Version Android Google Inc. 4.2 (Jelly Bean) iOS Apple Inc. 6.0.1 Windows Phone Microsoft 8.0 Device hardware not restricted, various Restricted to Apple vendors (smartphones, devices (iPod, iPhone, tablets) iPad, Apple TV) Various vendors, strictly defined hardware requirements OS Linux Kernel Mach/BSD Kernel App runtime Dalvik VM Native code on Mach/BSD Kernel WP7 - Win CE, WP8 – Windows NT Common Language Runtime Programming Java Language Objective-C, C (C++) C# Open source YES (Apache 2.0 license, some libs excluded, e.g. Google Maps) NO NO Development restrictions Any hardware and OS Apple Hardware and OS required Any hardware, Windows Company $299/year, Individual $99/year 99$ per year, free for students Developer program Dr. Thomas Springer development free Application Development - 9. Platforms 58 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/8 • 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 59