














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive introduction to android development, covering essential concepts, tools, and techniques. It guides beginners through the process of setting up the android sdk, creating virtual devices, and building their first android application. The document also explores key aspects of android architecture, including the linux kernel, android runtime, and application framework. It further delves into the use of the android emulator for testing and debugging applications.
Typology: Study notes
1 / 22
This page cannot be seen from the preview
Don't miss anything!















Syllabus: The Android 4.1 jelly Bean SDK, Understanding the Android Software Stack, installing the Android SDK, Creating Android Virtual Devices, Creating the First Android Project, Using the Text view Control, Using the Android Emulator, The Android Debug Bridge(ADB), Launching Android Applications on a Handset.
INTRODUCTION When we talked about operating systems few years ago, the most common answers were Windows, Linux, and mac operating system. However, with the undying competition in the mobile phones market, the next big thing entered was ANDROID, which in no time became the heart of smart phones. Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment.
Android is a mobile operating system developed by Google, based on a modified version of the Linux kernel and other open source software and designed primarily for touch screen mobile devices such as smart phones and tablets. In addition, Google has further developed Android TV for televisions, Android Auto for cars, and Wear OS for wrist watches, each with a specialized user interface. Variants of Android are also used on game consoles, digital cameras, PCs and other electronics.
The Android Operating System is a Linux-based OS developed by the Open Handset Alliance (OHA). The Android OS was originally created by Android, Inc., which was bought by Google in 2005. Google teamed up with other companies to form the Open Handset Alliance (OHA), which has become responsible for the continued development of the Android OS.
The android is a powerful operating system and it supports large number of applications in Smart phones. These applications are more comfortable and advanced for the users. The hardware that supports android software is based on ARM architecture platform. The android is an open source operating system means that it’s free and any one can use it.
The android has got millions of apps available that can help you managing your life one or other way and it is available low cost in market at that reasons android is very popular.
Each time the OHA releases an Android version, it names the release after a dessert. Android 1.5 is known as Cupcake, 1.6 as Donut, 2.0/2.1 as Eclair, 2.2 as Froyo and 2.3 is dubbed Gingerbread. Once a version is released, so is its source code.
The Android OS is designed for phones. The important features of android are given below:
Software developers who want to create applications for the Android OS can download the Android Software Development Kit (SDK) for a specific version. The SDK includes a debugger, libraries, an emulator, some documentation, sample code and tutorials. For faster development, interested parties
can use graphical integrated development environments (IDEs) such as Eclipse to write applications in Java.
Android Emulator:
The Emulator is a new application in android operating system. The emulator is a new prototype that is used to develop and test android applications without using any physical device.
The android emulator has all of the hardware and software features like mobile device except phone calls. It provides a variety of navigation and control keys. It also provides a screen to display your application. The emulators utilize the android virtual device configurations. Once your application is running on it, it can use services of the android platform to help other applications, access the network, play audio, video, store and retrieve the data.
of the Android Operating System. The code names of android ranges from A to N currently, such as Aestro, Blender, Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwitch, Jelly Bean, KitKat, Lollipop and Marshmallow. Let's understand the android history in a sequence.
UNDERSTANDING THE ANDROID SOFTWARE STACK/ Android Architecture
The Android operating system is built on top of a modified Linux kernel. The software stack contains Java applications running on top of a virtual machine. Components of the system are written in Java, C, C++, and XML. Android operating system is a stack of software components which is roughly divided into five sections
1) Linux kernel
It is the heart of android architecture that exists at the root of android architecture. Linux kernel is responsible for device drivers, power management, memory management, device management and resource access. This layer is the foundation of the Android Platform.
Contains all low level drivers for various hardware components support. Android Runtime relies on Linux Kernel for core system services like, Memory, process management, threading etc. Network stack Driver model Security and more.
2) Libraries
On top of Linux kernel there is a set of libraries including open-source Web browser engine WebKit, well known library libc, SQLite database which is a useful repository for storage and sharing of application data, libraries to play and record audio and video, SSL libraries responsible for Internet security etc.
SQLite Library used for data storage and light in terms of mobile memory footprints and task execution. WebKit Library mainly provides Web Browsing engine and a lot more related features. The surface manager library is responsible for rendering windows and drawing surfaces of various apps on the screen. The media framework library provides media codecs for audio and video. The OpenGl (Open Graphics Library) and SGL (Scalable Graphics Library) are the graphics libraries for 3D and 2D rendering, respectively. The FreeType Library is used for rendering fonts.
3) Android Runtime
In android runtime, there are core libraries and DVM (Dalvik Virtual Machine) which is responsible to run android application. DVM is like JVM but it is optimized for mobile devices. It consumes less memory and provides fast performance. The Dalvik VM makes use of Linux core features like memory management and multi-threading, which is intrinsic in the Java language. The Dalvik VM enables every Android application to run in its own process, with its own instance of the Dalvik virtual machine.
4) Android Framework
On the top of Native libraries and android runtime, there is android framework. Android framework includes Android API's such as UI (User Interface), telephony, resources, locations, Content Providers (data) and package managers. It provides a lot of classes and interfaces for android application development.
Dalvik is a specialized virtual machine designed specifically for Android and optimized for battery-powered mobile devices with limited memory and CPU. Android apps execute on Dalvik VM, a “clean-room” implementation of JVM Dalvik optimized for efficient execution Dalvik: register-based VM, unlike Oracle’s stack-based JVM Java .class bytecode translated to Dalvik EXecutable (DEX) bytecode, which Dalvik interprets
7
Android Studio is now ready and loaded with the Android developer tools, but there are still a couple packages you should add to make your Android SDK complete. 4)The SDK separates tools, platforms, and other components into packages you can download as needed using the Android SDK Manager. Make sure that you have downloaded all these packages. To start adding packages, launch the Android SDK Manager in one of the following ways: In Android Studio, click SDK Manager in the toolbar. If you're not using Android Studio: Windows: Double-click the SDK Manager.exe file at the root of the Android SDK directory. Mac/Linux: Open a terminal and navigate to the tools/ directory in the Android SDK, then execute android sdk. 5)Now get all the SDK tools, support libraries for additional APIs, Google Play services (if you need to use them ). 6)Once you've selected all the desired packages, continue to install: Click Install X packages. In the next window, double-click each package name on the left to accept the license agreement for each. Click Install. The download progress is shown at the bottom of the SDK Manager window. Do not exit the SDK Manager or it will cancel the download. 7)Now that we have downloaded and installed everything we need. Enjoy your experience with Android. Best of luck from Internshala.com
For developing native Android applications that you can publish on the Google Play marketplace, you need to install the following four applications:
The Android SDK is not a full development environment and includes only the core SDK Tools, which are used to download the rest of the SDK components. This means that after installing the Android SDK Tools, you need to install Android platform tools and the other components required for developing Android applications. Go
8
to http://developer.android.com/sdk/index.html and download the package by selecting the link for your operating system.
The first screen is a Welcome screen. Select the Next button to move to the next screen. Because the Android SDK requires the Java SE Development Kit for its operation, it checks for the presence of JDK on your computer.
If Java is already installed on your computer before beginning with Android SDK installation, the wizard detects its presence and displays the version number of the JDK found on the machine, as shown in Figure.
Figure Dialog box informing you that the JDK is already installed on the computer
Select the Next button. You get a dialog box asking you to choose the users for which Android SDK is being installed. The following two options are displayed in the dialog box:
Select the Install for anyone using this computer option and click Next. The next dialog prompts you for the location to install the Android SDK Tools, as shown in below Figure. The dialog also displays the default directory location for installing Android SDK Tools as C:\Program Files (x86)\Android\android-sdk, which you can change by selecting the Browse button. Keep the default directory for installing Android SDK Tools unchanged; then select the Next button to continue.
10
Figure: Successful installation of the Android SDK Tools dialog box
Note that the check box Start SDK Manager (to download system images) is checked by default. It means that after the Finish button is clicked, the Android SDK Manager, one of the tools in the Android SDK Tools package, will be launched. Android SDK is installed in two phases. The first phase is the installation of the SDK, which installs the Android SDK Tools, and the second phase is installation of the Android platforms and other components. An Android application is a combination of several small components that include Java files, XML resource and layout files, manifest files, and much more. It would be very time-consuming to create all these components manually. So, you can use the following applications to help you:
CREATING ANDROID VIRTUAL DEVICES
An Android Virtual Device (AVD) represents a device configuration. There are many Android devices, each with different configuration. To test whether the Android application is compatible with a set of Android devices, you can create AVDs that represent their configuration. For example, you can create an AVD that represents an Android device running version 4.1 of the SDK with a 64MB SD card. After creating AVDs, you point the emulator to each one when developing and testing the application. AVDs are the easiest way of testing the application with various configurations.
11
To create AVDs in Eclipse, select the Window, AVD Manager option. An Android Virtual Device Manager dialog opens, as shown in Figure. The dialog box displays a list of existing AVDs, letting you create new AVDs and manage existing AVDs. Because you haven’t yet defined an AVD, an empty list is displayed.
Figure: The AVD Manager dialog
Select the New button to define a new AVD. A Create new Android Virtual Device (AVD)dialog box, appears The fields are as follows:
Note You learn about the API and its different levels in Chapter 2, “Basic Widgets.” The new AVD, demoAVD, is created and displayed in the list of existing AVDs.
Note The larger the allocated SD Card space, the longer it takes to create the AVD. Unless it is really required, keep the SD Card space as low as possible. I would recommend keeping this small, like 64MiB.
13
Just click on the Add button as shown in the picture and add https://dl-ssl.google.com/android/eclipse/ as the location. When you press OK, Eclipse will start to search for the required plug-in and finally it will list the found plug- ins.
Step 3: Configuring the ADT plugin After the installing ADT plugin, now tell the eclipse IDE for your android SDK location. To do so:
14
Step 4: Create Android Virtual Device: The last step is to create Android Virtual Device, which you will use to test your Android applications. To do this, open Eclipse and Launch Android AVD Manager from options Window > AVD Manager and click on New which will create a successful Android Virtual Device. Use the screenshot below to enter the correct values.
In android ui or input controls are the interactive or View components which are used to design the user interface of an application. In android we have a wide variety of UI or input controls available, those are TextView, EditText, Buttons, Checkbox, Progressbar, Spinners, etc. In android, TextView is a user interface control which is used to set and display the text to the user based on our requirements. The TextView control will act as like label control and it won’t allow users to edit the text. A good example of TextView control usage would be to display textual labels for other controls, like "Enter a Date:", "Enter a Name:" or "Enter a Password:". In android, we can create a TextView control in two ways either in XML layout file or create it in Activity file programmatically. Specific attributes of TextView controls you will want to be aware of: Give the TextView control a unique name using the id property. Set the text displayed within the TextView control using the text property; programmatically set with the setText() method. Set the layout height and layout width properties of the control as appropriate. Set any other attributes you desire to adjust the control’s appearance. For example, adjust the text size, color, font or other style settings. By default, text contents of a TextView control are left-aligned. However, you can position the text using the gravity attribute. This setting positions your text relative to the control’s overall width and height and only really makes sense to use if there is whitespace within the TextView control. In XML, this property would appear within your TextView control as: android:gravity="center"
16
Limitations of the Android Emulator The Android emulator is useful to test Android applications for compatibility with devices of different configurations. But still, it is a piece of software and not an actual device and has several limitations:
17
You can also interact with an emulator from within the DDMS tool. Eclipse IDE provides three perspectives to work with: Java perspective, Debug perspective, and DDMS perspective. The Java perspective is the default and the one with which you have been working up to now. You can switch between perspectives by choosing the appropriate icon in the top-right corner of the Eclipse environment. The three perspectives are as follows:
THE ANDROID DEBUG BRIDGE(ADB)
The Android-Debug-Bridge (abbreviated as adb) is a software-interface for the android system, which can be used to connect an android device with a computer using an USB cable or a wireless connection. It can be used to execute commands on the phone or transfer data between the device and the computer.[1]
The tool is part of the Android SDK (Android Software Development Kit) and is located in the subdirectory platform- tools. In previous versions of the SDK it was located in the subdirectory tools.
The Android Debug Bridge is a software interface between the device and the local computer, which allows the direct communication of both components. This includes the possibility to transfer files from one component to the other one, as well as executing commands from the computer on the connected device. The ADB can be used through a command line windows, terminal/shell in Linux-based systems, a command line (cmd) for Windows. The main advantage is to execute commands on the phone directly out of the computer, without any direct user interaction to the phone, which makes especially debugging a lot easier.
It is a client-server program that includes three components:
A client , which sends commands. The client runs on your development machine. You can invoke a client from a command-line terminal by issuing an adb command. A daemon (adbd) , which runs commands on a device. The daemon runs as a background process on each device. A server , which manages communication between the client and the daemon. The server runs as a background process on your development machine.
When you start an adb client, the client first checks whether there is an adb server process already running. If there isn't, it starts the server process. When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate with the adb server. The server then sets up connections to all running devices. It locates emulators by scanning odd-numbered ports in the range 5555 to 5585, the range used by the first 16 emulators. Where the server finds an adb daemon (adbd),
19
1). idea: This folder contains the directories (subfolders) for IntelliJ IDEA settings.
app: It contains the actual application code(source files, resource file and manifest files). It further contains the following sub-directories : a) bulid: This folder has sub-folders for the build-variants. The app/build/output/apk directory contains packages named app-
src: Here you will see two sub-directories androidTest and main. In androidTest the application code for testing purpose is created by android automatically. This helps in building testing packages without modifying the building files and the application code.
main contains the all the source .java files including the stub mainactivity.java.
The res directory is where you will find the resources like drawable files, menu, values ( style files, string values, dimension values).
Sub-directories of res folder anim/: For XML files that are compiled into animation objects. color/: For XML files that describe colors.
20
drawable/:For image files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). mipmap/: For app launcher icons. This folder contains additional sub-folders for different screen resolutions. Once an image is imported into this folder, Studio automatically resizes the image into different resolutions and places them in the appropirate folders. This behavior allows launcher apps to pick the best resolution icon for your app to display on the home screen. To see how to import an image into the mipmap folder, please read about using 'Image asset'. layout/: XML files that are compiled into screen layouts (or parts of a parent layout). menu/: For XML files that define application menus. values/: For XML files that define constants that can be accessed in other XML and Java files.
R.java
R.java is an uneditable file auto-generated by Studio, whenever we modify the XML content. This file links the XML values to Java files. Whenever we need to use XML values in a Java file, we call these values using the R class. The following images show a sample XML file, where a string variable named 'title' is assigned a value of 'Internshala - Tic Tac Toe'. This variable is then accessed in a java file using the R class.
What is Build system and Gradle
The build system is responsible to build, test an android system and also prepare the deployable files for the specified platform. In simple words, build system generates the .apk files for the application project.
With Android Studio, the advanced build system allows the developers to configure the build systems manually, create different variant APK files from single project (without modifying the execution code) and share the code and resources from other modules. Before Android Studio, Eclipse was the IDE used for android development. Eclipse kept all the .java files (in src directory) and resource files (in res directory) in the same directory. That allows the build system to group all the files into an intermediate code and finally generates .apk file. Android Studio uses Gradle as its build system. One intriguing feature that Gradle offers is that it allows you to write your own script to automate the task of building an app. As Gradle is plug-in based system, if you have your own programming language then you can write the plug-in in the script using java or groovy and share it with other developers too. Isn`t that cool?