Introduction to ANDROID
Introduction Mobile operating system that is based on a modified version of Linux. Developed by Google and later the Open Handset Alliance (OHA) Allows writing managed code in the Java language Unveiling of the Android platform was announced on 5 November 2007 with the founding of OHA
History of Android Google acquired the startup company Android Inc. in 2005 to start the development of the Android Platform. The key players at Android Inc. included Andy Rubin, Rich Miner, Nick Sears, and Chris White. In late 2007, a group of industry leaders came together around the Android Platform to form the Open Handset Alliance (http://www.openhandsetalliance.com). The Android SDK was first issued as an “early look” release in November 2007. In September 2008 T-Mobile announced the availability of the T-Mobile G1, the first smartphone based on the Android Platform. A few days after that, Google announced the availability of Android SDK Release Candidate 1.0. In October 2008, Google made the source code of the Android Platform available under Apache’s open source license.
What is Open Handset Alliance? “… Open Handset Alliance™, a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer, less expensive, and better mobile experience. Together we have developed Android™, the first complete, open, and free mobile platform. We are committed to commercially deploy handsets and services using the Android Platform. “
Introduction → It's a consortium of several companies Google Android What is the Open Handset Alliance (OHA)? → It's a consortium of several companies Google Android
Open Handset Alliance Members
Phones HTC G1, Droid, Tattoo Motorola Droid (X) Sony Ericsson Suno S880 Samsung Galaxy 7
Tablets Velocity Micro Cruz Gome FlyTouch Acer beTouch Toshiba Android SmartBook Cisco Android Tablet Dawa D7 8
OHA Google goes wireless Forming the OHA Manufacturers : Designing the android handsets Mobile Operators : Delivering the android experience Content Providers: Developing Android apps
Android’s Context: Mobile Market Player Stakeholders: Mobile network operators want to lock down their networks, controlling and metering traffic. Device manufacturers want to differentiate themselves with features, reliability, and price points. Software vendors want complete access to the hardware to deliver cutting- edge applications.
Android Versions
Version and API Alpha (1.0) ----- 1 Beta (1.1) ----- 2 Cupcake (1.5) ----- 3 Donut (1.6) ----- 4 Eclair (2.0–2.1) ----- 5,6,7 Froyo (2.2–2.2.3) ----- 8 Gingerbread (2.3–2.3.7) ----- 9,10 Honeycomb (3.0–3.2.6) ----- 11,12,13 Ice Cream Sandwich (4.0–4.0.4) ----- 14,15 Jelly Bean (4.1–4.3.1) ----- 16,17,18 KitKat (4.4–4.4.4) ----- 19,20 Lollipop (5.0–5.0.2) ----- 21
Features of Android Storage Connectivity Messaging Web browser Media support Hardware support Multi-touch Multi-tasking Flash support Tethering
Platform - The Android Software Stack 14
Android S/W Stack - Application Android provides a set of core applications: Email Client SMS Program Calendar Maps Browser Contacts Etc All applications are written using the Java language. 15
Android S/W Stack – App Framework Most of the application framework accesses these core libraries through the Dalvik VM, the gateway to the Android Platform 16
Android S/W Stack – App Framework (Cont) 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 string , graphics, and layout files) Notification Manager Enabling all applications to display customer alerts in the status bar Activity Managing the lifecycle of applications and providing a common navigation backstack 17
Location Manager
Notification Manager
Notification Manager How background app interact with users Consistent notification presentation
View System
View System
Android S/W Stack - Libraries Including a set of C/C++ libraries used by components of the Android system Exposed to developers through the Android application framework 23
Android S/W Stack - Libraries The media libraries are based on PacketVideo’s (http://www.packetvideo.com/) OpenCORE. These libraries are responsible for recording and playback of audio and video formats. A library called Surface Manager controls access to the display system and supports 2D and 3D. The WebKit library is responsible for browser support; it is the same library that supports Google Chrome and Apple Inc.’s Safari. The FreeType library is responsible for font support. SQLite (http://www.sqlite.org/) is a relational database that is available on the device itself. SQLite is also an independent open source effort for relational databases and not directly tied to Android. You can acquire and use tools meant for SQLite for Android databases as well.
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 25
The Dalvik runtime is optimised for mobile applications Run multiple VMs efficiently Each app has its own VM Minimal memory footprint
Android S/W Stack – Runtime (Cont) Dalvik Virtual Machine (Cont) Executing the Dalvik Executable (.dex) format .dex format is optimized for minimal memory footprint. Compilation Relying on the Linux Kernel for: Threading Low-level memory management 27
Android applications are compiled to Dalvik bytecode Write app in Java Compiled in Java Transformed to Dalvik bytecode Linux OS Loaded into Dalvik VM
Android S/W Stack – Linux Kernel Relying on Linux Kernel 2.6 for core system services Memory and Process Management Network Stack Driver Model Security The supplied device drivers include Display, Camera, Keypad, WiFi, Flash Memory, Audio, and IPC (interprocess communication). Providing an abstraction layer between the H/W and the rest of the S/W stack @2010 Mihail L. Sichitiu 29
Platform Google Android Network Connectivity It supports wireless communications using: GSM mobile-phone technology 3G Edge 802.11 Wi-Fi networks Google Android
Software development Google Android Development requirements Java Android SDK Google Android
Software development Google Android IDE and Tools Android SDK Android SDK Class Library Developer Tools Emulator and System Images Documentation and Sample Code Eclipse IDE + ADT (Android Development Tools) Reduces Development and Testing Time Makes User Interface-Creation easier Makes Application Description Easier Google Android
Advantages Google Android Here are a few other advantages Android offers you as a developer: The Android SDK is available for Windows, Mac and Linux, so you don’t need to pay for new hardware to start writing applications. An SDK built on Java. If you’re familiar with the Java programming language, you’re already halfway there. By distributing your application on Android Market, it’s available to hundreds of thousands of users instantly. You’re not just limited to one store, because there are alternatives, too. For instance, you can release your application on your own blog. Amazon have recently been rumoured to be preparing their own Android app store also. As well as the technical SDK documentation, new resources are being published for Android developers as the platform gains popularity among both users and developers. Google Android
Application Building Blocks Activity IntentReceiver Service ContentProvider
Activities Typically correspond to one UI screen But, they can: Be faceless Be in a floating window Return a value
IntentReceivers Components that respond to broadcast ‘Intents’ Way to respond to external notification or alarms Apps can invent and broadcast their own Intent
Intents Think of Intents as a verb and object; a description of what you want done E.g. VIEW, CALL, PLAY etc.. System matches Intent with Activity that can best provide the service Activities and IntentReceivers describe what Intents they can service
Intents “Pick photo” Photo Gallery Home Picasa Contacts GMail Chat Blogger Blogger
Services Faceless components that run in the background E.g. music player, network download etc…
ContentProviders Enables sharing of data across applications E.g. address book, photo gallery Provides uniform APIs for: querying delete, update and insert. Content is represented by URI and MIME type
Android Development Framework
Android software Development Kit (SDK) includes : Android APIs Development Tools The Android Virtual Device Manager and Emulator Full Documentation Sample Code Online Support- http://developer.android.com/support.html
DVM Dalvik is open-source software. Dan Bornstein originally wrote Dalvik VM which is responsible for running apps on Android devices. It is a Register based Virtual Machine. It is optimized for low memory requirements. It has been designed to allow multiple VM instances to run at once. Relies on the underlying OS for process isolation, memory management and threading support. Operates on DEX files. All hardware and system service access is managed using Dalvik (middle tier)
Development Environment JDK Software Development Kit (SDK) IDE – Eclipse Eclipse plug-in - ADT Android Emulator, Virtual Device Manager Debugger – Dalvik Debug Monitoring Service(DDMS) Android Asset Packaging Tool (AAPT) --- .apk Android Debug Bridge( ADB)
Setup Android SDK Download Android SDK and extract the zip file to an arbitrary folder http://androidappdocs.appspot.com/sdk/index.html E.g.: extract to C:\ The SDK will be used by ADT in eclipse(located in adt- bundle../eclipse
Setup ADT plugin Install Eclipse ADT plugin Eclipse must be J2EE edition Update site: https://dl- ssl.google.com/android/eclips e/ Install all the plugins in the repository Restart needed after installation
Configure ADT Plugin Open eclipse Window->Preferences, select Android Setup the SDK location as the folder where you extracted the downloaded SDK zip file
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
An Android Virtual Device (AVD) is a configuration of emulator options An AVD includes: A hardware profile A platform Other options ▪e.g., emulator skin, screen dimensions, SD card size A storage area Create AVDs using Android SDK and AVD Manager tool
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
Ready… Now you may start the AVD Click start to start the new AVD First start-up may take a very long time
1. DDMS What’s happening under the surface Debugging tool -- to interrogate active processes, view stack, watch and pause active threads ADB Client server app – to connect with android emulator. 3 components- daemon running in emulator - service that runs on your hardware - client app that communicate with daemon through service
Android SDK Documentation Home SDK --- version and NDK, release notes Dev Guide -- Design and development Reference – Android APIs Resources – Technical articles and tutorials Videos Blog
Developing for mobile devices Hardware imposed design consideration Be Efficient Expect Limited Capacity Design for small screens Expect low speeds, high latency At what cost
Android Component’s life cycle
Android Components Broadcast Receivers Content Providers Services and Activities.
During execution of onReceive() ---- alive As soon as onReceive() returns ---destroyed. Because of this short lifetime there are some restrictions on what you can do inside this function. For example, its invalid to use bindService() or registerReceiver() functions from inside onReceive().
Static and dynamic broadcast receivers Static broadcast --- AndroidManifest.xml dynamic ----- registerReceiver() function.
Content Provider content providers are never destroyed, they exist for the entire lifetime of their process. It is considered alive on call to onCreate() and until process that contains this component is killed. shutdown(). ---introduced in API Level 11 and may be implemented by Content Provider. Unit tests may call it in order to guarantee unit test isolation.
Service service is alive between calls to onCreate() and onDestroy() functions.
Activity Refer Activity Life Cycle concepts
‘Hello World’ on Android
Create a new Android Project Open File->New- >Android project Project name Build Target Application name Package name Create Activity
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
Say Hello World modify HelloWorld.java
Run Hello World Select HelloWorld Project, Run->Run as->Android Application ADT will start a proper AVD and run HelloWorld app on it
Behind HelloWorld #1 R.java, generated by Android SDK, represents all the resources of the app. resources are all in res folder resources are pre-compiled into binary format /* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */ package sample.hello; public final class R { public static final class attr { } public static final class drawable { public static final int icon=0x7f020000; public static final class layout { public static final int main=0x7f030000; public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000;
Behind HelloWorld #2 res/layout , contains layout declarations of the app, in XML format, UIs are built according to the layout file Linear Layout main.xml <?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> TextView, display static text A reference to String resource ‘hello’
Behind HelloWorld #3 res/values, contains string declarations or other values(e.g.:colors) of the app string.xml, contains string resources <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, HelloWorld!</string> <string name="app_name">HelloWorld</string> </resources> referenced in res/layout/main.xml referenced in AndroidManifest.xml
Behind HelloWorld #4 res/drawable, contains all image resources folders may have suffixes, app will choose the most suitable one, so do the other resources three folders: drawable-ldpi, drawable-hdpi, drawable-mdpi, each contains an icon.png file app will choose the proper icon according to the device DPI reference name:@drawable/icon other folders we may use in future menu, anim (animation), xml ( preference and searchable)
Behind HelloWorld #5 AndroidManifest.xml describe the application declare app’s name, version, icon, permission, etc… declare the application's components: activity, service ,receiver or provider <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="sample.hello" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloWorld" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER”/> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="8" /> </manifest>
Core Components-Activity #1 Basically, An activity presents a visual user interface for one focused endeavor the user can undertake An application might consist of just one activity or several, each Activity is derived from android.app.Activity and should be declared in AndroidManifest.xml file Each activity is given a default window to draw in, the window may be full screen or smaller and on top of other window The visual content of the window is provided by a hierarchy of views — objects derived from the base View class Activity.setContentView() method is used to set a certain hierarchy of view objects
Core Components-Activity #2 Activities are activated by asynchronous messages called intents An intent is an Intent object that holds the content of the message The action being requested or the URI of the data to act on The <intent-filter> label in AndroidManifest.xml file specifies the Intent that can start the Activity declares the main activity, it will be started automatically when the app starts An activity is launched (or given something new to do) by passing an Intent object to Context.startActivity() or Activity.startActivityForResult()
Activity lifecycle
Other Core Components Service Broadcast receivers Content providers A service doesn't have a visual user interface, runs in the background for a period of time Broadcast receivers a component that does nothing but receive and react to broadcast announcements Content providers A content provider makes a specific set of the application's data available to other applications. The data can be stored in the file system, in an SQLite database, or in any other manner that makes sense
Beyond HelloWorld #1 Build up an app that you can input your greetings and display your greetings Input: EditText Display: TextView Of course, we have to add an button Edit res/layout/main.xml file to add these components each has an android:id property, used to reference it in code
Beyond HelloWorld #2 modify HelloWorld.java firstly get the references declared in main.xml then add event response for Button
Beyond HelloWorld #3 Finished! Run->Run as->Android Application Quite easy, isn’t it?
More…
Useful Materials Android Official Site http://www.android.com Android SDK, Tutorial, Concepts and API docs http://androidappdocs.appspot.com/index.html Android Development Community http://www.anddev.org/ 30 Days Android Apps Development http://bakhtiyor.com/category/30-days-of-android-apps/