Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Application Development

Similar presentations


Presentation on theme: "Android Application Development"— Presentation transcript:

1 Android Application Development
CPE 401/601 Modified from Mihail L. Sichitiu, Dick Steflik, Ramya Balaraman Siddharth Kaza - Josh Dehlinger

2 What is Android? Android is a software stack for mobile devices that includes an operating system, middleware and key applications. An open source Linux-based operating system intended for mobile computing platforms Includes a Java API for developing applications It is not a device or product 2

3 Android and the Hardware
Built-in Apps ≡ Apps created in SDK Leverage Linux kernel to interface with hardware Open source platform promotes development from global community In the Android platform, there is no difference between the built-in applications and applications created with the SDK. This means that powerful applications can be written to tap into the resources available on the device. Android is software only. Leveraging its Linux kernel to interface with the hardware, you can expect Android to run on many different devices from multiple cell phone manufacturers. Android is an open source platform; missing elements can and will be provided by the global developer community. Android’s Linux kernel–based OS does not come with a sophisticated shell environment, but because the platform is open, shells can be written and installed on a device. Likewise, multimedia codecs can be supplied by third-party developers and do not need to rely on Google or anyone else to provide new functionality. That is the power of an open source platform brought to the mobile market. Ableson, Frank; Collins, Charlie; Sen, Robi. Unlocking Android, A Developer’s Guide. Greenwich: Manning Publications Co 3

4 By Touch Revolution – at CES 2010
Android-Powered Microwave By Touch Revolution – at CES 2010

5 Android-Powered Car Radio

6 Android-Powered Washing Machine

7 Brief History 1996 The WWW already had websites with color and images
But, the best phones displayed a couple of lines of monochrome text! Enter: Wireless Application Protocol (WAP) – stripped down HTTP for bandwidth reduction Wireless Markup Language (WML) – stripped down HTML for content

8 Brief History Many issues (WAP = “Wait And Pay”)
Few developers to produce content (it wasn’t fun!) Really hard to type in URLs using the small keyboards Data fees frightfully expensive No billing mechanism – content difficult to monetize Other platforms emerged Palm OS, Blackberry OS, J2ME, Symbian (Nokia), BREW, OS X iPhone, Windows Mobile

9 Brief History - Android
2005 Google acquires startup Android Inc. to start Android platform Work on Dalvik VM begins 2007 Open Handset Alliance announced Early look at SDK 2008 Google sponsors 1st  Android Developer Challenge T-Mobile G1 announced SDK 1.0 released Android released open source (Apache License) Android Dev Phone 1 released  Open Handset Alliance, a consortium of 47 hardware, software, and telecom companies devoted to advancing open standards for mobile devices. Includes Texas Instruments, Broadcom Corporation, Google, HTC, Intel, LG, Marvell Technology Group, Motorola, Nvidia, Qualcomm, Samsung Electronics, Sprint Nextel and T-Mobile 9

10 Brief History cont. 2009 2010 SDK 1.5 (Cupcake) SDK 1.6 (Donut)
New soft keyboard with “autocomplete” feature SDK 1.6 (Donut) Support Wide VGA SDK 2.0/2.0.1/2.1 (Eclair) Revamped UI, browser 2010 Nexus One released to the public SDK 2.2 (Froyo) Flash support, tethering SDK 2.3 (Gingerbread) UI update, system-wide copy-paste 10

11 Brief History cont. 2011 2012 SDK 3.x (Honeycomb)
Optimized for tablet support SDK 4.0 (Ice Cream Sandwich) Virtual UI buttons 2012 SDK (Jelly Bean) Triple buffered graphics pipeline 11

12 Brief History cont. 2011 Honeycomb
SDK 3.0/3.1/3.2 (Honeycomb) for tablets only New UI for tablets, support multi-core processors SDK 4.0/4.0.1/4.0.2/4.0.3 (Ice Cream Sandwich) Changes to the UI, Voice input, NFC Ice cream Sandwich Android 4.0+ Jelly Bean Android 4.1.1 Honeycomb Android 12

13 Mobile Devices: Advantages
Always with the user Typically have Internet access Typically GPS enabled Typically have accelerometer & compass Most have cameras & microphones Many apps are free or low-cost Maybe more profitable with ads than actually selling the app 13

14 Mobile Devices: Disadvantages
Limited screen size Limited battery life Limited processor speed Limited and sometimes slow network access Limited or awkward input: soft keyboard, phone keypad, touch screen, or stylus Limited web browser functionality Range of platforms & configurations across device

15 What is Google Android? A software stack for mobile devices that includes An operating system Middleware Key Applications Uses Linux to provide core system services Security Memory management Process management Power management Hardware drivers

16 Android Apps Built using Java and new SDK libraries
No support for some Java libraries like Swing & AWT Java code compiled into Dalvik byte code (.dex) Optimized for mobile devices (better memory management, battery utilization, etc.) Dalvik VM runs .dex files

17 What is iOS Apple’s mobile OS for phones (iPhone), tablets (iPad), handhelds (iPod), based on BSD Unix Application programming done in Objective C Supports Bluetooth, Wi-Fi, and 3G and 4G networking

18 Android Application Development
SDK Eclipse IDE Android Mobile Device Android Emulator

19 iOS Application Development
SDK XCODE IDE iOS Mobile Device iOS Simulator

20 Android development Java Source Android Manifest Generated Class
Java Compiler .dex File Dalvik VM Resource XML Android Libraries

21 iOS development Xcode Objective C Source Interface Builder .xib file
Objective C Compiler . Simulator or Device Foundation Framework Cocoa Libraries

22 NATIVE APPS Binary executable files on the device.
Can access all API’s made available by OS vendor. SDK’s are platform-specific. Each mobile OS comes with its own unique tools and GUI toolkit. Different tools, languages and distribution channels associated with leading mobile operating systems * IBM, Native, web or hybrid mobile app development, IBM Software Thought Leadership White Paper

23 NATIVE APPS CONS PROS Code Reusability : Low
Easy low-level hardware access services. Easy access to high level services important to personal mobile experience. Full use of all functionalities that modern mobile devices have to offer. High usability. CONS Code Reusability : Low Development & maintenance: Time-consuming & expensive. Designers are required to be familiar with different UI components of each OS. Upgrade flexibility: Low. Once the app is installed, it interacts with the underlying operating system through proprietary API calls that the OS exposes. These are divided into 2 categories – Low-level API’s & high level API’s. Through low-level API calls, the app can interact directly with the touchscreen or keyboard, render graphics, connect to networks, process audio received from the microphone, receive images & video from the camera, access the GPS etc. Higher level services include processes like browsing the web, managing calendar, contacts, photo album, the ability to send and receive phone calls etc. 23

24 CROSS-COMPILATION Separates build environment from target environment.
Platform-independent API using a mainstream programming language like JavaScript, Ruby or Java. The cross-compiler then transforms the code into platform-specific native apps. The software artifact generated can be deployed and executed natively on the device. ADVANTAGES: Improved performance and User Experience. Full access to functionalities of underlying mobile OS and device specific capabilities. DISADVANTAGES: Highly complex as cross-compilers are difficult to program. Need to be kept consistent with fragmented mobile platforms and operating systems available. Developers can use this API to build the application including UI, data persistence & business logic. The code is then processed by the compiler and transformed into platform-specific native apps. High performance as the app is running natively on the device & improved user experience as the app has full native access to all device-specific capabilities such as integrated camera, sensors etc. 24

25 VIRTUAL MACHINE APPROACH
A virtual machine is used to abstract the target platform details from the application’s running code. The framework provides both the API and runtime environment. The runtime executes on the mobile device and enables interoperability between the device’s OS and the mobile application. ADVANTAGES: Improved performance and User Experience. Full access to functionalities of underlying mobile OS and device specific capabilities. Portability: VM’s are easier to maintain & more flexible to extend. DISADVANTAGES: Slower due to runtime interpretation latency. VM’s :easier to extend when new features are added to the device and need to be supported by the API Runtime interpretation latency introduced when the VM is translating data and instructions to & from the underlying host platform. 25

26 MOBILE WEB APPS Use standard web technologies such as HTML 5, CSS 3 & JavaScript. Features of HTML 5 - Advanced UI components, access to rich media types, geolocation services & offline availability. Increasing popularity of HTML 5 in rendering engines such as WebKit. Runs on a standalone mobile web browser. Installed shortcut, launched like a native app. UI logic resides locally; makes the app responsive and accessible offline. ADVANTAGES: Multiplatform support. Low development cost. Leverage existing knowledge. DISADVANTAGES: Limited access to OS API’s. Another increasingly popular approach is to develop mobile web apps which run on the user’s mobile browser. These are different from mobile-optimized websites which detect when they are being accessed from a mobile device and serve HTML pages that have been designed to provide a comfortable touch experience on a small screen size. This involves using standard web technologies such as HTML, CSS, JavaScript to build the application & make it look and behave like a native app. It is possible due to the advanced capabilities of HTML 5 including embedded SQL databases, local storage (application cache to reduce page startup time and enable offline features), animations, canvas (avoid transferring images), websockets, video playback, geolocation services etc. Mobile Google Search uses the HTML5 Geolocation API to show location-aware results. Google Maps for Mobile and Mobile Gmail both use the canvas tag to avoid transferring images. This approach may be appealing for many applications such as ebooks, mobile banking, social interaction & . However it may not be suited for highly interactive, CPU-intensive, visually rich applications like games, augmented reality browsers & videoconferencing. 26

27 HYBRID APPS Combines native development with web technology.
The web app runs inside a thin wrapper native app. The wrapper native app uses the OS API’s to create an embedded HTML rendering engine which provides a bridge between the browser and device API’s. The communication between web app and native app normally happens over JavaScript via custom built API’s. ADVANTAGES: Flexibility of web apps combined with feature richness of native apps. Simplified deployment and immediate availability. Leverage existing knowledge. DISADVANTAGES: Poorer user experience as compared to native apps. Access to advanced device capabilities normally restricted. The bridge enables the hybrid app to take full advantage of all the features that modern devices have to offer. App developers can choose to code their own bridge or use ones provided by many of the cross-platform development frameworks such as PhoneGap. 27

28 CROSS-PLATFORM FRAMEWORKS
PROS Code Reusability Plugins Easy for web developers Reduced development costs Support for enterprise & cloud services Easy Deployment CONS Might not support every feature of OS Cannot use own tools/IDE Slower. High end graphics & 3D support limited Vendor lock-in Major frameworks, including Appcelerator and PhoneGap offer easy access to plugins and modules that can easily plug into other services or tools. Do not have to invest in a team or developer specific to that ecosystem. In addition to plugins and modules for specific functions, most frameworks also have the option to directly integrate with cloud services, including Salesforce.com, AWS, Box.net and others. Deploying and compiling apps is much faster in a cross-platform scenario. This is especially true with many of the new cloud-based build tools that various frameworks are starting to push out. If Google, Apple or Microsoft adds a new feature, the framework you are using will need to be updated to support those new additions. Most frameworks want users to use their own development tools and suites, and that can mean that a developer has to forgo his or her own IDE preferences and use something else. Most of the cross-platform frameworks build using their own subsets of JavaScript, which means that if you want to switch to another platform, that code you wrote before is likely not going to be reusable without a lot of work. 28

29 CROSS-PLATFORM FRAMEWORKS
*

30 Android architecture Modified from Yi Huang

31 Android architecture 31

32 Linux Kernel Note that Android based on a Linux kernel not a Linux OS
Supplies Security, Memory management, Process management, Network stack and Driver model Acts as an abstraction layer between the hardware and the rest of the software stack 32

33 Libraries Run in system background Using C/C++ Language
4 types of Libraries Bionic Libc, system C libraries Function Libraries, supporting multimedia, web browser, SQLite... Native Servers Hardware Abstraction Libraries 33

34 Core Libraries System C library, the standard C system library, tuned for embedded Linux-based devices Media Libraries, support playback and recording of many popular audio and video formats, as well as image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG Surface Manager, manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications WebKit, a modern web browser engine which powers both the Android browser and an embeddable web view SGL, the underlying 2D graphics engine 3D libraries, an implementation based on OpenGL ES 1.0 APIs FreeType , bitmap and vector font rendering SQLite , a powerful and lightweight relational database engine 34

35 Andoid Runtime The core of Android platform Dalvik Virtual Machine
Register-based Executes files in the Dalvik Executable (.dex) format Java core Libraries Provides most of the functionality of the Java programming language. 35

36 DVM vs. JVM DVM Google Dalvik executable Only supports a subset of standard Java Library JVM Sun Java bytecode Some worries that Java world may be divided into different communities, each has its own Java standard 36

37 Application Framework
Simplify the reuse of components Applications can publish their capabilities and any other application may then make use of those capabilities Applications is a set of services and systems, include Views system, content providers, resources manager and so on 37

38 Application Framework (cont.)
Activity Manager, manages the lifecycle of applications and provides a common navigation backstack Notification Manager, enables all applications to display custom alerts in the status bar Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files Content Providers, access data from other applications (such as Contacts), or to share their own data Views, used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser 38

39 Applications A set of core applications shipped with Android platform
an client, SMS program, calendar, maps, browser, contacts, and others All written in Java Our applications are in the same level as these applications 39

40 Application Fundamentals
Apps are written in Java Every App runs its own Linux process Each process has it’s own Java Virtual Machine Each App is assigned a unique Linux user ID Apps can share the same user ID to see each other’s files Android applications are written in the Java programming language. The compiled Java code — along with any data and resource files required by the application — is bundled by the Android Asset Packaging Tool into an Android package, an archive file marked by an .apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices; it's the file users download to their devices. All the code in a single .apk file is considered to be one application. In many ways, each Android application lives in its own world: By default, every application runs in its own Linux process. Android starts the process when any of the application's code needs to be executed, and shuts down the process when it's no longer needed and system resources are required by other applications. Each process has its own Java virtual machine (VM), so application code runs in isolation from the code of all other applications. By default, each application is assigned a unique Linux user ID. Permissions are set so that the application's files are visible only that user, only to the application itself — although there are ways to export them to other applications as well. It's possible to arrange for two applications to share the same user ID, in which case they will be able to see each other's files. To conserve system resources, applications with the same ID can also arrange to run in the same Linux process, sharing the same VM. 40

41 Hardware-oriented Features
Description Camera A class that enables your application to interact with the camera to snap a photo, acquire images for a preview screen, and modify parameters used to govern how the camera operates. Sensor Class representing a sensor. Use getSensorList(int) to get the list of available Sensors. SensorManager A class that permits access to the sensors available within the Android platform. SensorEventListener An interface used for receiving notifications from the SensorManager when sensor values have changed. An application implements this interface to monitor one or more sensors available in the hardware. SensorEvent This class represents a sensor event and holds information such as the sensor type (e.g., accelerometer, orientation, etc.), the time-stamp, accuracy and of course the sensor's data. MediaRecorder A class, used to record media samples, that can be useful for recording audio activity within a specific location (such as a baby nursery). Audio clippings can also be analyzed for identification purposes in an access-control or security application. For example, it could be helpful to open the door to your time-share with your voice, rather than having to meet with the realtor to get a key. GeomagneticField This class is used to estimated estimate magnetic field at a given point on Earth, and in particular, to compute the magnetic declination from true north. FaceDetector A class that permits basic recognition of a person's face as contained in a bitmap. Using this as a device lock means no more passwords to remember — biometrics capability on a cell phone. Developer’s are able to access “goodies” Hardware capabilities made available This table describes some of the hardware-oriented features exposed in the Android SDK. 41

42 What Should We Already Know?
Java! inheritance, method overriding interfaces, casting exceptions debugging reading API documentation 42

43 Development process for an Android app

44 Publishing and Monetizing
Paid apps in Android Market, various other markets Free, ad-supported apps in Android Market Ad networks (Google AdMob, Quattro Wireless) Sell your own ads Contests (Android Developer Challenge) Selling products from within your app

45 Publishing to Google Play
Requires Google Developer Account $25 fee Link to a Merchant Account Google Checkout Link to your checking account Google takes 30% of app purchase price

46 Android Design Philosophy
Applications should be: Fast Resource constraints: <200MB RAM, slow processor Responsive Apps must respond to user actions within 5 seconds Secure Apps declare permissions in manifest Seamless Usability is key, persist data, suspend services Android kills processes in background as needed

47 Copyright ©2010 Lauren Darcey and Shane Conder
Important callback methods of the activity life cycle During the life of an activity, the system calls a core set of lifecycle methods in a sequence similar to a step pyramid. Copyright ©2010 Lauren Darcey and Shane Conder 47

48 Android software development
Modified from Yi Huang

49 Development Environment
IDE – Eclipse Eclipse plug-in - ADT Software Development Kit (SDK) Android Emulator Debugger

50 Setup Android SDK Download Android SDK and extract the zip file to an arbitrary folder E.g.: extract to C:\ The SDK will be used by ADT in eclipse 50

51 Setup ADT plugin Install Eclipse ADT plugin
Eclipse must be J2EE edition, 3.5 recommended Update site: Install all the plugins in the repository Restart needed after installation 51

52 Configure ADT Plugin Open eclipse Window->Preferences, select Android Setup the SDK location as the folder where you extracted the downloaded SDK zip file 52

53 Setup SDK APIs Open Window->Android SDK and AVD Manager
Click Available Packages and then choose proper APIs to install, the latest may be the best 53

54 Setup Emulators After SDK APIs installation, click Virtual Devices
Click new, there will be a dialog input a name choose a running target and a skin specify the SD card size 54

55 Ready… Now you may start the AVD Click start to start the new AVD
First start-up may take a very long time 55

56 “Hello, Android” Modified from Chris Murphy 56

57 Creating Your First(?) Android App
Set up your development environment Create a new Android project in Eclipse Run it in the emulator 57

58 2. Create an Android Project in Eclipse
File → New → Project Select “Android Project” Fill in Project details... 58

59 Directory name Android version Java package Name that appears
on device Class to automatically create 59

60 Hello World Project src: source folder gen: SDK generated file
android 2.2: reference lib assets: binary resources res: resource files and resource description files AndroidManifest.xml: application description file default.properties: project properties file 60

61 HelloAndroid.java 1 public class HelloAndroid extends Activity {
2  /** Called when the activity is first created. */ 4    public void onCreate(Bundle savedInstanceState) 5 { 6      super.onCreate(savedInstanceState); 7        setContentView(R.layout.main); 8    } 9 } 61

62 main.xml 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout 3 xmlns:android=" 4 android:orientation="vertical" 5 android:layout_width="fill_parent" 6 android:layout_height="fill_parent" 7 > 8 <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" 11 " /> 13 </LinearLayout> 62

63 strings.xml 1 <?xml version="1.0" encoding="utf-8"?>
2 <resources> 3 <string name="hello">Hello World, HelloAndroid! 4 </string> 5 <string name="app_name">Hello, Android</string> 6 </resources> 63

64 AndroidManifest.xml 1 <?xml version="1.0" encoding="utf-8"?>
3 xmlns:android=" 4 package="edu.unr.cpe401" 5 android:versionCode="1" 6 android:versionName="1.0"> 7 <application 8 <activity android:name=".HelloAndroid" 10 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> 18 </application> 19 </manifest> 64

65 3. 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 65

66 66

67 Programming Tutorial Accessing a website from the Android Emulator
Modified from Deepa Shinde and Cindy Atherton 67

68 Layout 68

69 Link Activity and View View object may have an integer ID associated with it To get the reference of the view object in activity Button myButton = (Button)findViewById(R.id.my_button); 69

70 Adding Event to View Object
View.OnClickListener() Interface definition for a callback to be invoked when a view is clicked.  onClick(View v) Called when a view has been clicked. Inside this function you can specify what actions to perform on a click. 70

71 Strings.xml 71

72 AndroidManifest.xml 72

73 Online Resources http://developer.android.com
videos from Google I/O conferences 73


Download ppt "Android Application Development"

Similar presentations


Ads by Google