40
Day2

Day2

Embed Size (px)

DESCRIPTION

Day2. Contents. What’s Android Android architecture Android software development ‘ Hello World ’ on Android More…. What’s Android. Android Phones. Mobile Devices. It’s obvious that mobile device may take the place of PC in future OS plays a vital part. OHA and Android. - PowerPoint PPT Presentation

Citation preview

Day1

Day2ContentsWhats AndroidAndroid architectureAndroid software developmentHello World on AndroidMore2Whats Android3Android Phones4

Mobile DevicesIts obvious that mobile device may take the place of PC in futureOS plays a vital part5

6

OHA and AndroidOHA(Open Handset Alliance) is a group of 71 technology and mobile companies, including Google, Intel, Dell, HTC and China MobileOHAs aimaccelerate innovation in mobile phonesoffer consumers a richer, less expensive, and better mobile experienceOHA developed Android, the first complete, open, and free mobile platformOHA was initially called up by Google, and Google is the captain7Whats AndroidGenerally, Android is a software stack for mobile devices that includes an operating system, middleware and key applications Android is based on JAVA and all its applications are developed in JAVAThe JAVA VM, known as Dalvik, is highly customized and optimized for mobile devicesAndroid SDK offers rich tools for android application development and many useful APIs8

The core of AndroidAndroid Features #1Application framework enabling reuse and replacement of components Optimized Java virtual machine: DalvikOptimized Graphics Processing, supporting 2D and 3D graphics(OpenGL ES 1.0 )Integrated open source web browser: WebKitSQLite for structured data storage9Android Features #2Multimedia capability, supporting varieties of audio, video and still image formatsGSM TelephonyBluetooth, EDGE, 3G and Wi-Fi supportCamera, GPS, compass, accelerometer and other sensors support Rich development environment, including an emulator, debugging tools, memory probe tools, log tools and powerful eclipse plugins10Hardware dependentAndroid architecture

1112

Linux KernelNote that Android based on a Linux kernel not a Linux OSSupplies Security, Memory management, Process management, Network stack and Driver model Acts as an abstraction layer between the hardware and the rest of the software stack13

LibrariesRun in system backgroundUsing C/C++ Language4 types of LibrariesBionic Libc, system C librariesFunction Libraries, supporting multimedia, web browser, SQLite...Native ServersHardware Abstraction Libraries

14

Core LibrariesSystem C library, the standard C system library, tuned for embedded Linux-based devicesMedia 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 PNGSurface Manager, manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applicationsWebKit, a modern web browser engine which powers both the Android browser and an embeddable web viewSGL, the underlying 2D graphics engine3D libraries, an implementation based on OpenGL ES 1.0 APIsFreeType , bitmap and vector font renderingSQLite , a powerful and lightweight relational database engine15Andoid RuntimeThe core of Android platformDalvik Virtual MachineRegister-basedExecutes files in the Dalvik Executable (.dex) formatJava core LibrariesProvides most of the functionality of the Java programming language.16

Android Runtime (cont.)The functions of Java core libraries rely on the Dalvik VM and the underlying Linux kernelMultiple Dalvik VMs may run at the same timeEvery Android application runs in its own process, with its own instance of the Dalvik virtual machineThe "dx" tool in Android SDK can transform compiled JAVA class into the .dex format17Dalvik Virtual MachineAndroid custom implementation virtual machineProvides application portability and runtime consistencyRuns optimized file format (.dex) and Dalvik bytecodeJava .class / .jar files converted to .dex at build timeDesigned for embedded environmentSupports multiple virtual machine processes per deviceHighly CPU-optimized bytecode interpreterEfficiently Using runtime memoryCore LibrariesCore APIs for Java language provide a powerful, yet simple and familiar development platform18DVM vs. JVMDVMGoogleDalvik executableOnly supports a subset of standard Java LibraryJVMSunJava bytecodeSome worries that Java world may be divided into different communities, each has its own Java standard19Application FrameworkSimplify the reuse of componentsApplications can publish their capabilities and any other application may then make use of those capabilitiesApplications is a set of services and systems, include Views system, content providers, resources manager and so on

20

Application Framework (cont.)Activity Manager, manages the lifecycle of applications and provides a common navigation backstackNotification Manager, enables all applications to display custom alerts in the status barResource Manager, providing access to non-code resources such as localized strings, graphics, and layout filesContent Providers, access data from other applications (such as Contacts), or to share their own dataViews, used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser21ApplicationsA set of core applications shipped with Android platforman email client, SMS program, calendar, maps, browser, contacts, and othersAll written in JavaOur applications are in the same level as these applications22

Android software development

23Development EnvironmentIDE Eclipse Eclipse plug-in - ADTSoftware Development Kit (SDK)Android EmulatorDebuggerSetup Android SDKDownload Android SDK and extract the zip file to an arbitrary folderhttp://androidappdocs.appspot.com/sdk/index.htmlE.g.: extract to C:\The SDK will be used by ADT in eclipse

25

Setup ADT pluginInstall Eclipse ADT pluginEclipse must be J2EE edition, 3.5 recommendedUpdate site: https://dl-ssl.google.com/android/eclipse/Install all the plugins in the repositoryRestart needed after installation

26

Configure ADT PluginOpen eclipse Window->Preferences, select AndroidSetup the SDK location as the folder where you extracted the downloaded SDK zip file27

Setup SDK APIsOpen Window->Android SDK and AVD ManagerClick Available Packages and then choose proper APIs to install, the latest may be the best28

Setup EmulatorsAfter SDK APIs installation, click Virtual Devices Click new, there will be a dialoginput a name choose a running target and a skin specify the SD card size 29

ReadyNow you may start the AVDClick start to start the new AVDFirst start-up may take a very long time 30

Hello World on Android

31Create a new Android ProjectOpen File->New->Android projectProject nameBuild TargetApplication namePackage nameCreate Activity

32

Hello World Projectsrc: source foldergen: SDK generated fileandroid 2.2: reference libassets: binary resourcesres: resource files and resource description filesAndroidManifest.xml: application description filedefault.properties: project properties file33

Say Hello Worldmodify HelloWorld.java

34

Run Hello WorldSelect HelloWorld Project, Run->Run as->Android ApplicationADT will start a proper AVD and run HelloWorld app on it

35

Behind HelloWorld #1R.java, generated by Android SDK, represents all the resources of the app. resources are all in res folderresources are pre-compiled into binary format36/* 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; }}

Linear LayoutBehind HelloWorld #2res/layout , contains layout declarations of the app, in XML format, UIs are built according to the layout file37main.xml

TextView, display static textA reference to String resource helloreferenced in res/layout/main.xmlBehind HelloWorld #3res/values, contains string declarations or other values(e.g.:colors) of the appstring.xml, contains string resources38

Hello World, HelloWorld! HelloWorld

referenced in AndroidManifest.xmlBehind HelloWorld #4res/drawable, contains all image resourcesfolders may have suffixes, app will choose the most suitable one, so do the other resourcesthree folders: drawable-ldpi, drawable-hdpi, drawable-mdpi, each contains an icon.png fileapp will choose the proper icon according to the device DPIreference name:@drawable/iconother folders we may use in futuremenu, anim (animation), xml ( preference and searchable)39

Behind HelloWorld #5AndroidManifest.xml describe the applicationdeclare apps name, version, icon, permission, etcdeclare the application's components: activity, service ,receiver or provider

40