android deep dive

Download Android deep dive

Post on 05-Jul-2015




4 download

Embed Size (px)


Android : Lesson 1 Introduntion Android Features Android Versions Android Devices Android Architecture Example 1: Hello World Anatomy of Android Application


  • 1. By Dr. Anu Sahni

2. Why Android Introduction What is Android Introduction More about Android Android Devices Android versions Android Architecture Example 1 Running Hello World on Emulator and device1. 2. 3. 4. 5. 6. 7. i. ii. iii.8.Creating first project Hello World Running Hello World on Emulator Running Hello World on real deviceAnatomy of Android ApplicationNote: All the names and examples are for illustration purpose only and should be replaced according to your environment. 3. The most recent data from IDC shows that forQ3 of 2013 Android made up 81 percent of devices shipped with Samsung making 53 percent of the profit for the quarter Apples iOS scraped by with a sad and distant second place figure of only 12.9 percent with 56 percent of the profit in the mobile device market HTC, LG, Motorola, Nokia, and BlackBerry lost money 4. Apple leads Android in enterpriseadoption, and in retail shopping use by consumers The volume of apps available in the Google Play app store has caught up to Apple, and Android is winning in app downloads as well. Google reportedly comprises 75 percent of all app downloads, compared to only 18 percent for Apple. 5. Android is a mobile operating system basedon modified version of Linux Open and free under Apache License Developers have access to the source code Vendors (Samsung, Motorola, Sony Ericsson) canadd propriety extensions Same program runs on different devices running Android 6. No fixed hardware and software asmanufactures can customise freely Storage uses SQLite for database Connectivity Android provides rich APIs to letyour app connect and interact with other devices over Bluetooth, NFC, Wi-Fi P2P, USB, and SIP, in addition to standard network connections. 7. Web browser based on open-source WebKit withChrome V8 JavaScript engine Media supports H.264, AAC and HE-AAC (in 3GP or MP4 container) MP3, MIDI, Ogg Vorbis Wav - compatible with Windows, Macintosh, and Linux operating systems JPEG, PNG, GIF, BMP 8. Hardware support AccelerometerSensor, Camera, Digital Compass, Proximity Sensor, and GPS Multi-touch supports multi-touch screens Multi-tasking supports multi-tasking apps Tethering supports Internet connections sharing such as wired/wireless hotspot 9. Smartphones Tablets E-reader devices Notebook MP4 players Android TV 10. VersionCodenameAPIDistribution2.2Froyo81.6%2.3.3 2.3.7Gingerbread1024.1%3.2Honeycomb130.1%4.0.3 4.0.4Ice Cream Sandwich1518.6%1637.4%1712.9%184.2%191.1%4.1.x 4.2.xJelly Bean4.3 4.4KitKat 11. Linux Kernel (layer 1): contains all lowlevel device drivers for Android hardware components Libraries (layer 2): contains code for the main features provided by Android OS. For example SQLite library for database support and WebKit library for web browsing feature 12. Android runtime (layer 2): contains core libraries to enable developers to write codes in Java. Also includes Dalvik virtual machine, designed specifically for Android and optimised for battery powered mobile devices with limited memory and CPU. All apps are compiled into Dalvik exe Application Framework: exposes various capabilities of Android OS to enable developers to include them in their apps such as camera Applications: contains apps that come with the device such as Phone, Contacts, Browser and all the 3rd party apps that you install. 13. Launch Eclipse Click New in thetoolbar. In the window that appears, open the Android folder if it is not already open , select Android Application Project, and click Next as shown in Figure 1.Figure 1. The New Android App Project wizard in Eclipse. 14. Fill in the form that appears: Application Name is the app name that appears to users. For this project, use Hello World." Project Name is the name of your project directory and the name visible in Eclipse. Package Name is the package namespace for your app that must be unique across all packages installed on the Android system. Common practice is to use the name in reverse order - domain name of your organization first followed by the project name. For example, "com.example.helloworld. Read the warning. Read the comment.Figure 1. The New Android App Project wizard in Eclipse. 15. Minimum Required SDK is thelowest version of Android that your app supports, indicated using the API level. Leave this set to the default value for this project. Target SDK indicates the highest version of Android (also using the API level) with which you have tested with your application. Setting the build target to the latest version allows you to enable new features and optimize your app for a great user experience on the latest devices. Figure 1. The New Android App Project wizard in Eclipse. 16. Compile With is theplatform version against which you will compile your app. By default, this is set to the latest version of Android available in your SDK. Theme specifies the Android UI style to apply for your app. You can leave this alone. Click Next. Figure 1. The New Android App Project wizard in Eclipse. 17. On the next screen to configure theproject, leave the default selections and click Next. The next screen can help you create a launcher icon for your app. Click Next. Select BlankActivity as your activity template and click Next. Leave all the details for the activity in their default state and click Finish. 18. An Android Virtual Device (AVD) is a device configuration for the Android emulator that allows you to model different devices. Follow the steps below to create an AVD: Launch the Android Virtual Device Manager Window Android VirtualDevice Manager . 19. In the Android Virtual Device Manager panel, clickNew. Fill in the details for the AVD. Give it a name, a platform target, an SD card size, and a skin (HVGA is default). Click Ok. Select the new AVD from the Android Virtual Device Manager and click Start. Starting Android Emulator window starts the emulator, AVD2 in this case. Close the Starting Android Emulator window after the emulator shows up. 20. Once the AVD is created, select the Projectname and click Run As from the toolbar. 21. Select Android Application and click OK. 22. Select the AVD on which you want to run theapp 23. Launch Hello World 24. Plug in your device to your development machine with a USB cable. Install the appropriate USB driver for your device. Enable USB debugging on your device. On most devices running Android 3.2 or older, you can findthe option under Settings Applications Development. On Android 4.0 and newer, it's in Settings Developer options. On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings About phone and tap Build number seven times. Return to the previous screen to find Developer options. 25. Run the app fromEclipse: Right click the projectand select Run As Run Configurations 26. Select Launchon all compatible devices/AVDs Select Active devices from the dropdown Click Run 27. All apps are created as projects. Folders and files that make up an Android project: src: contains the .java source files for yourproject. For example, is the source file of the main activity of the app. Unlike Java programs that have entry only through the main method, an Android activity may have more than 1 entry points. For example, you can call Camera app from your app resulting an additional entry point for the Camera app 28. gen: contains config file is a compiler generated file and contains the references to all the resources in project. Note 1: Dont modify Note 2: as you add more files and folders to your project, Eclipse automatically generates the contents of Note 3: if you accidently delete, Eclipse will regenerate it for you immediately provided there are no errors. 29. Android 4.2: contains android.jar, which containsall the class libraries used for project. For example, security, opengl, accessibility, animation, etc. 30. Android Dependencies: containsJAR files your project depends on and the assets folder. For example, the Support Package includes static "support libraries" that you can add to your Android application in order to use APIs that are either not available for older platform versions or that offer "utility" APIs that aren't a part of the framework APIs. The goal is to simplify your development by offering more APIs that you can bundle with your application so you can worry less about platform versions. assets: contains all the assets used by the project such as HTML, database. 31. bin: During the build process, your Android projects are compiled and packaged into an .apk file, the container for your application binary. It contains all of the information necessary to run your application on a device or emulator, such as compiled .dex files (.class files converted to Dalvik byte code), a binary version of the AndroidManifest.xml file, compiled resources (resources.arsc) and uncompiled resource files for your application. The ADT plugin incrementally builds your project as you make changes to the source code. Eclipse outputs an .apk file automatically to the bin folder of the project, so you do not have to do anything extra to generate the .apk. 32. libs: contains all Java libraries that can be packaged and distributed using the Java Archive Format (also called JAR). There are a number of Android-compatible libraries that can be leveraged within your Android applications provided they are linked properly to your project . Theses JAR files are automatically picked by Eclipse. For example package, android-supportv4.jar. 33. res: contains all theresources used by the project plus a few subfolders such as drawable , layout, a nd values. 34. AndroidManifest.xml: The manifest file describes the fundamental characteristics of the appand defines each of its components. You specify all the permissions needed by your app, a