0% found this document useful (0 votes)
99 views55 pages

Mad ch1 2 Notes

Android is a mobile operating system developed by Google that supports a wide range of devices and includes a software development kit for app creation. The document outlines the history of Android versions, the Open Handset Alliance's role in its development, and the ecosystem surrounding Android, which includes users, developers, and manufacturers. It also highlights the features and development tools available for Android, emphasizing its open-source nature and integration with Google services.

Uploaded by

divyamundlik21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views55 pages

Mad ch1 2 Notes

Android is a mobile operating system developed by Google that supports a wide range of devices and includes a software development kit for app creation. The document outlines the history of Android versions, the Open Handset Alliance's role in its development, and the ecosystem surrounding Android, which includes users, developers, and manufacturers. It also highlights the features and development tools available for Android, emphasizing its open-source nature and integration with Google services.

Uploaded by

divyamundlik21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Android

What is Android?
Android is an operating system and programming platform developed by Google for smartphones
and other mobile devices (such as tablets). It can run on many different devices from many
different manufacturers. Android includes a software development kit for writing original code
and assembling software modules to create apps for Android users. It also provides a
marketplace to distribute apps. Altogether, Android represents an ecosystem for mobile apps.

Android versions
Google did not attach any high-calorie code name to its initial versions 1.0 and 1.1 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.

Fig. Android versions

Release Date Version API Level Version Name

September 23, 2008 Android 1.0 1 Apple Pie

February 9, 2009 Android 1.1 2 Banana Bread

April 30, 2009 Android 1.5 3 Cupcake

September 15, 2009 Android 1.6 4 Donut

October 26, 2009 Android 2.0 5 Eclair

December 3, 2009 Android 2.0.1 6

January 12, 2009 Android 2.1 7

May 20, 2010 Android 2.2 8 Froyo

Prepared by Mrs. [Link] 1


Release Date Version API Level Version Name

January 18, 2011 Android 2.2.1 8

January 22, 2011 Android 2.2.2 8

November 21, 2011 Android 2.2.3 8

December 6, 2010 Android 2.3 9 Gingerbread

February 9, 2011 Android 2.3.1 9

July 25, 2011 Android 2.3.3 10

September 2, 2011 Android 2.3.4 10

February 22, 2011 Android 3.0.x 11 Honeycomb

May 10, 2011 Android 3.1.x 12

July 15, 2011 Android 3.2.x 13

October 18,2011 Android 4.0 14 Ice Cream Sandwich

October 19, 2011 Android 4.0.1 14

November 28, 2011 Android 4.0.2 14

December 16, 2011 Android 4.0.3 15

February 4, 2012 Android 4.0.4 15

July 9, 2012 Android 4.1 16 Jelly Bean

July 23, 2012 Android 4.1.1 16

October 9, 2012 Android 4.1.2 16

November 13, 2012 Android 4.2 17

November 27, 2012 Android 4.2.1 17

February 11, 2013 Android 4.2.2 17

July 24, 2013 Android 4.3 18

October 31, 2013 Android 4.4 19 Kitkat

June 23, 2014 Android 4.4.1, 4.4.2, 4.4.3, 19

Prepared by Mrs. [Link] 2


Release Date Version API Level Version Name

4.4.4

October 17, 2014 Android 5.0 21 Lollipop

March 09, 2015 Android 5.1 22

October 5, 2015 Android 6.0 23 Marshmallow

December 7, 2015 Android 6.0.1 23

August 22, 2016 Android 7.0 24 Nougat

October 4, 2016 Android 7.1 25

August 21, 2017. Android 8.0 26 Oreo

December 5, 2017 Android 8.1 27 Android Oreo (Go edition)

August 6, 2018 Android 9.0 28 Pie

September 3, 2019 Android 10.0 29 Android Q(Quince Tart)

Feb 19,2020 Android 11.0 30 Android R(Red Velvet Cake)

October 2021 Android version 12 31,32 Snow Cone

August 2022 Android version 13 33 TIRAMISU

The Dashboard for Platform Versions is updated regularly to show the distribution of active devices
running each version of Android, based on the number of devices that visit the Google Play Store.
It's a good practice to support about 90% of the active devices, while targeting your app to the latest
version.

Open Handset Alliance (OHA):


The Open Handset Alliance (OHA) is a consortium whose goal is to develop open standards
for mobile devices, promote innovation in mobile phones and provide a better experience for
consumers at a lower cost.
 The Open Handset Alliance is made up of telecom-related entities, including wireless
carriers, semiconductor companies, handset manufacturers and software companies. However,
several major wireless companies and manufacturers are absent from the coalition, including Nokia,
Symbian, Apple, RIM, Microsoft, Verizon and Cingular.
 Google and 33 other companies announced the formation of the Open Handset Alliance on
November 5, 2007. According to the joint press release from that day:
This alliance shares a common goal of fostering innovation on mobile devices and giving consumers
a far better user experience than much of what is available on today’s mobile platforms.

Prepared by Mrs. [Link] 3


 By providing developers a new level of openness that enables them to work more
collaboratively, Android will accelerate the pace at which new and compelling mobile services are
made available to consumers.
 For us as mobile application developers, that means we are free to develop whatever creative
mobile applications we can think of, free to market them (or give them, at our option) to Android
mobile phone owners, and free to profit from that effort any way we can. Each member of the Open
Handset Alliance has its own reasons for participating and contributing its intellectual property, and
we are free to benefit.
 The Open Handset Alliance integrates contributed software and other intellectual property
from its member companies and makes it available to developers through the open source community.
 Software is licensed through the Apache V2 license, which you can see at
[Link] Use of the Apache license is critical, because it
allows handset manufacturers to take Android code, modify it as necessary, and then either keep it
proprietary or release it back to the open source community, at their option.
 The original Alliance members include handset manufacturers (HTC, LG, Motorola,
Samsung), mobile operators (China Mobile Communications, KDDI, DoCoMo, Sprint/Nextel, T-
Mobile, Telecom talia, Telefonica), semiconductor companies (Audience, Broadcom, Intel, Marvell,
NVidia Qualcomm, SiRF, Synaptics), software companies (Ascender, eBay, esmertec, Google,
LivingImage, LiveWire, Nuance, Packet Video, SkyPop, SONiVOX), and commercialization
companies (Aplix, Noser, TAT, Wind River). The Alliance includes the major partners needed to
deliver a platform for mobile phone applications in all of the major geographies.
 The Alliance releases software through Google’s developer website
([Link] The Android SDK for use by application software developers can be
downloaded directly from that website.
 The OHA introduced a mobile device operating system called Android Symbian operating
system.

Android ecosystem:

Prepared by Mrs. [Link] 4


Ecosystem in Market terminology refers to the inter-dependence between demand and supply.
In the Android ecosystem this translates to inter-dependence between users, developers, and
equipment makers. One cannot exist without the other:
 Users buy devices and applications
 Equipment makers sell devices, sometimes bundled with applications
 Developers buy devices, then make and sell applications

Fig . The Android ecosystem thrives with device compatibility

 An open source platform for mobile, embedded and wearable devices .


 Google is the principle maintainer
 Other companies contribute to the system.
Prepared by Mrs. [Link] 5
 Each device manufacturer can customize Android to suit their needs

Mobile Ecosystem is a collection of multiple devices (mobile phones, Tablet, Phablet etc), software
operating system, development tools, testing tools etc), companies (device manufacturers, carrier,
apps stores, development/testing companies) etc. and the process by which data (sms, bank-
transactions etc.) is transferred/shared by a user from one device to another device or by the device
itself based on some programs (Birthday, Wedding Messages, Calendar). Data (Text, Multi-media,
and VOICE) sharing can be done between devices of the same operating system or different operating
systems. Examples – Iphone (IOS) to Windows Phone, Iphone IOS to Nexus(Android),
Motorola(Android) to Nexus(Android). Data can also be shared between multiple devices with the
same operating system of the same manufacturer.

This new ecosystem is built and developed in order to drive the usage of apps. The end-users gain
access to several mobile apps just because of their popularity. Thus, the ecosystem of mobile
applications enables the enterprises and the independent developers to develop attractive, feature-
rich and unique mobile applications which will perform rapidly and can essentially garner the
attention of the market.
Android's source code has been used as the basis of different ecosystems, most notably that of Google
which is associated with a suite of proprietary software called Google Mobile Services (GMS), that
frequently comes pre-installed on the devices. This includes core apps such as Gmail, the digital
distribution platform Google Play and associated Google Play Services development platform, and
usually apps such as the Google Chrome web browser. These apps are licensed by manufacturers of
Android devices certified under standards imposed by Google. Other competing Android ecosystems
include [Link]'s Fire OS, or LineageOS. Software distribution is generally offered through
proprietary application stores like Google Play Store or Samsung Galaxy Store, or open source
platforms like Aptoide or F-Droid, which utilize software packages in the APK format.

Need of android:
There are many reasons to choose android operating system like
1. Open source
2. Large developer and community reach
3. Increased marketing
4. Inter App Integration
5. Reduced cost of development
6. Higher success ratio
7. Rich development environment
8. Variety
9. Widgets
10. Multi-tasking
11. Google Integration

Prepared by Mrs. [Link] 6


1. Reduced cost of development: The development tools like Android studio, Android SDK, JDK,
and Eclipse IDE etc. are free to download for the android mobile application development.
2. Open Source: The Android OS is an open-source platform based on the Linux kernel and
multiple open-source libraries. In this way developers are free to contribute or extend the
platform as necessary for building mobile apps which run on Android devices.
3. Multi-Platform Support: In market, there are a wide range of hardware devices powered by the
Android OS, including many different phones and tablet. Even development of android mobile
apps can occur on Windows, Mac OS or Linux.
4. Multi-Carrier Support: World wide a large number of telecom carriers like Airtel, Vodafone,
Idea Cellular, AT&T Mobility, BSNL etc. are supporting Android powered phones.
5. Open Distribution Model: Android Market place (Google Play store) has very few restrictions
on the content or functionality of an android app. So the developer can distribute theirs app
through Google Play store and as well other distribution channels like Amazon’s app store.
6. Multi-tasking: Multi-tasking is available on virtually all smartphone platforms but hardly does
any operating system do it better than android. Some manufacturers, e.g. Samsung allows for
multi-window tasking. This allows users to view multiple apps at the same time.
7. Variety: Android has provided a medium that has allowed smartphone manufacturers like
Samsung, HTC, ZTE, Sony and Motorola to allow their imagination run wild. On Android
platform, there is something for everyone regardless of taste or budget. Android offers flexibility
that is not obtainable with other platforms.
8. Widgets: Widget is another thing that is working absolutely well on Android devices. It has
worked so excellently, other operating systems and mobile app development are starting to adopt
something similar, e.g. the Live Tile System in Windows phone. Widget allows users to access
all the necessary information they want right from the screen, at a glance, without having to
launch an app.
9. Google Integration: Google, the current owners of Android, are highly smart in business.
Android devices work seamlessly with all of Google's products; Google Docs, Gmail, YouTube,
Google Music, Google Maps, Google Chrome, Google+ etc. Google is regarded as the king of
the web. This is a major attraction for most people, as having an android device gives them instant
access to all of this important software.

Prepared by Mrs. [Link] 7


Features of Android

Sr. Feature & Description


No.

1 Beautiful UI : Android OS basic screen provides a beautiful and intuitive user interface.

2 Connectivity: GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC
and WiMAX.

3 Storage: SQLite, a lightweight relational database, is used for data storage purposes.

4 Media support: H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1,
MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP.

5 Messaging: SMS and MMS

6 Web browser: Based on the open-source WebKit layout engine, coupled with Chrome's
V8 JavaScript engine supporting HTML5 and CSS3.

7 Multi-touch: Android has native support for multi-touch which was initially made available
in handsets such as the HTC Hero.

8 Multi-tasking: User can jump from one task to another and same time various application
can run simultaneously.

9 Resizable widgets: Widgets are resizable, so users can expand them to show more content
or shrink them to save space.

10 Multi-Language: Supports single direction and bi-directional text.

11 GCM: Google Cloud Messaging (GCM) is a service that lets developers send short message
data to their users on Android devices, without needing a proprietary sync solution.

12 Wi-Fi Direct: A technology that lets apps discover and pair directly, over a high-bandwidth
peer-to-peer connection.

13 Android Beam: A popular NFC-based technology that lets users instantly share, just by
touching two NFC-enabled phones together.

ANDROID DEVELOPMENT TOOLS


 Editors and IDEs
Prepared by Mrs. [Link] 8
 Language Resources
 Libraries
 Plug-ins Android Editors and IDEs

 System Requirements:
Following are the ideal system requirements for developing Android Apps
 Windows
 Microsoft® Windows® 7/8/10 (32- or 64-bit)
 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator
 2 GB of available disk space minimum, 4 GB Recommended (500 MB for IDE + 1.5
GB for Android SDK and emulator system image)
 1280 x 800 minimum screen resolution
 For accelerated emulator: Intel® processor with support for Intel® VT-x, Intel®
EM64T (Intel® 64), and Execute Disable (XD) Bit functionality
 Mac
 Mac® OS X® 10.10 (Yosemite) or higher, up to 10.12 (macOS Sierra)
 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator
 2 GB of available disk space minimum,4 GB Recommended (500 MB for IDE + 1.5
GB for Android SDK and emulator system image)
 1280 x 800 minimum screen resolution
 Linux
 GNOME or KDE desktopTested on Ubuntu® 14.04 LTS, Trusty Tahr (64-bit distribution
capable of running 32-bit applications)
 64-bit distribution capable of running 32-bit applications
 GNU C Library (glibc) 2.19 or later
 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator
 2 GB of available disk space minimum,4 GB Recommended (500 MB for IDE + 1.5 GB
for Android SDK and emulator system image)
 1280 x 800 minimum screen resolution
 For accelerated emulator: Intel® processor with support for Intel® VT-x, Intel® EM64T
(Intel® 64), and Execute Disable (XD) Bit functionality, or AMD processor with support
for AMD Virtualization™ (AMD-V™)
 Recommended Processor
More than i3, i5 or i7 developers should be concerned about the speed of the processor
and number of cores. 2Ghz Quad core Intel i3 processor would be enough to develop on
Android. I have personally used it and did not face any difficulty.

 IDE (Eclipse or Android Studio)


Although the SDK can be used to write Android programs in the command prompt,
the most common method is by using an integrated development environment (IDE). You all
might be aware of eclipse if you have ever developed anything in Java. Eclipse is quite reputed
and trusted IDE. And a lot of people use it for Android development too. But now a days
Android Studio is preferable, especially if you are a beginner.
Because

Prepared by Mrs. [Link] 9


i) Android Studio is a Google product – these are the same guys who develop Android.
ii) Android Studio uses Grade Build system. Which is quite faster than Eclipse’s
Apache Ant
iii) Android Studio’s Autocomplete feature quite better than that of Eclipse
iv) Designing UI has always been complex but Android Studio has completely changed
this. The new interface design too in Android Studio is faster, responds to changes
more rapidly and has more customization options that with Eclipse
Android SDK
The Android SDK (software development kit) is a set of development tools used to
develop applications for Android platform. The Android SDK includes the following:
 Required libraries
 Debugger
 An emulator
 Relevant documentation for the Android application program interfaces (APIs)
 Sample source code
 Tutorials for the Android OS

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
2) Native libraries (middleware)
3) Android Runtime
4) Application Framework
5) Applications

Prepared by Mrs. [Link] 10


Fig. Android architecture

Prepared by Mrs. [Link] 11


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.
Positioned at the bottom of the Android software stack, the Linux Kernel provides a level of
abstraction between the device hardware and the upper layers of the Android software stack. Based
on Linux version 2.6, the kernel provides pre-emptive multitasking, low-level core system services
such as memory, process and power management in addition to providing a network stack and
device drivers for hardware such as the device display, Wi-Fi and audio.
 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
Prepared by Mrs. [Link] 12
security etc.
In addition to a set of standard Java development libraries (providing support for such general purpose
tasks as string handling, networking and file manipulation), the Android development environment
also includes the Android Libraries. These are a set of Java-based libraries that are specific to Android
development. Examples of libraries in this category include the application framework libraries in
addition to those that facilitate user interface building, graphics drawing and database access.
A summary of some key core Android libraries available to the Android developer is as follows:
 [Link] – Provides access to the application model and is the cornerstone of all Android
applications.
 [Link] – Facilitates content access, publishing and messaging between applications
and application components.
 [Link] – Used to access data published by content providers and includes SQLite
database management classes.
 [Link] – A low-level 2D graphics drawing API including colors, points, filters,
rectangles and canvases.
 [Link] – Presents an API providing access to hardware such as the accelerometer
and light sensor.
 [Link] – A Java interface to the OpenGL ES 3D graphics rendering API.
 [Link] – Provides applications with access to standard operating system services including
messages, system services and inter-process communication.
 [Link] – Provides classes to enable playback of audio and video.
 [Link] – A set of APIs providing access to the network stack. Includes [Link]. wifi,
which provides access to the device’s wireless stack.
 [Link] – Includes a set of classes that enable content to be sent to configured printers
from within Android applications.
 [Link] – A set of convenience classes that provide access to standard Android content
provider databases such as those maintained by the calendar and contact applications.
 [Link] – Used to render and manipulate text on a device display.
 [Link] – A set of utility classes for performing tasks such as string and number conversion,
XML handling and date and time manipulation.
 [Link] – The fundamental building blocks of application user interfaces.
 [Link] - A rich collection of pre-built user interface components such as buttons, labels,
list views, layout managers, radio buttons etc.
 [Link] – A set of classes intended to allow web-browsing capabilities to be built into
applications.
Having covered the Java-based libraries in the Android runtime, it is now time to turn our attention
to the C/C++ based libraries contained in this layer of the Android software stack.
C/C++ Libraries
The Android runtime core libraries outlined in the preceding section are Java-based and provide the
primary APIs for developers writing Android applications. It is important to note, however, that the
core libraries do not perform much of the actual work and are, in fact, essentially Java “wrappers”
around a set of C/C++ based libraries. When making calls, for example, to the android. opengl library

Prepared by Mrs. [Link] 13


to draw 3D graphics on the device display, the library actually ultimately makes calls to the OpenGL
ES C++ library which, in turn, works with the underlying Linux kernel to perform the drawing tasks.
C/C++ libraries are included to fulfil a wide and diverse range of functions including 2D and
3D graphics drawing, Secure Sockets Layer (SSL) communication, SQLite database
management, audio and video playback, bitmap and vector font rendering, display subsystem
and graphic layer management and an implementation of the standard C system library (libc).
In practice, the typical Android application developer will access these libraries solely through the
Java based Android core library APIs. In the event that direct access to these libraries is needed, this
can be achieved using the Android Native Development Kit (NDK), the purpose of which is to call
the native methods of non-Java or Kotlin programming languages (such as C and C++) from within
Java code using the Java Native Interface (JNI).
 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.
When an Android app is built within Android Studio it is compiled into an intermediate bytecode
format (referred to as DEX format). When the application is subsequently loaded onto the device, the
Android Runtime (ART) uses a process referred to as Ahead-of-Time (AOT) compilation to translate
the bytecode down to the native instructions required by the device processor. This format is known
as Executable and Linkable Format (ELF).
Each time the application is subsequently launched, the ELF executable version is run, resulting in
faster application performance and improved battery life.
This contrasts with the Just-in-Time (JIT) compilation approach used in older Android
implementations whereby the bytecode was translated within a virtual machine (VM) each time the
application was launched.

Prepared by Mrs. [Link] 14


Fig. Android Runtime
 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
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.
The Application Framework is a set of services that collectively form the environment in which
Android applications run and are managed. This framework implements the concept that Android
applications are constructed from reusable, interchangeable and replaceable components. This
concept is taken a step further in that an application is also able to publish its capabilities along with
any corresponding data so that they can be found and reused by other applications.
The Android framework includes the following key services:
• Activity Manager: manages the life cycle of an applications and maintains the back stack as well
so that the applications running on different processes has smooth navigations.
• Package Manager: keeps track of which applications are installed in your device.
• Window Manager: Manages windows which are java programming abstractions on top of lower
level surfaces provided by surface manager.
• Telephony Managers: manages the API which is used to build the phone applications
• Content Providers: Provide feature where one application can share the data with another
application, like phone number, address, etc.
• View Manager: Buttons, Edit text, all the building blocks of UI, event dispatching etc.
 Resource Manager: Provides access to non-code embedded resources such as strings, colour
settings and user interface layouts.
Prepared by Mrs. [Link] 15
 Notifications Manager: Allows applications to display alerts and notifications to the user.
 Location Manager: Provides access to the location services allowing an application to receive
updates about location changes
5) Applications
On the top of android framework, there are applications. These comprise both the native applications
provided with the particular Android implementation (for example web browser and email
applications) and the third party applications installed by the user after purchasing the device. All
applications such as home, contact, settings, games, browsers are using android framework that uses
android runtime and libraries.
Android runtime and native libraries are using Linux kernel. Any applications that you write are
located at this layer.

The Android Operating System:


Android is an open-source mobile operating system. It is a variant of Linux hence providing
extensive security, modularity and productivity at the mobile device level.
Originally, Android was created by a company called Android Inc. Google acquired this
company in 2005. After then, Google made it open source.
Android has seven major releases each having several minor revisions. In order to follow these
versions easier, developers name them with cookie names. The popular versions of Android are
Kitkat (Android 4.4), Lollipop (Android 5.1) and Marshmallow (Android 6.0), Nougat (Android 7.0)
is also gaining popularity.
Android is utilized not only in smartphones but also in tablets, netbooks, digital television boxes,
handheld game devices and even in single board computers such as UDOO. UDOO is a single-board
computer with an integrated Arduino Due compatible microcontroller, designed for computer
science education, the world of Makers and the Internet of Things.

How do Android Apps Work?

Fig. : Working of Android Apps

There are different ways the programs run on various platforms. The lowest level software
can be written in machine code that runs directly on the microprocessor. This is shown in Figure
Since it is difficult to develop complex applications in machine code, operating systems are used.
Operating systems provide a communication and control layer between the application software and
the hardware as shown in Figure. If we want to develop a native application for running on a specific
Prepared by Mrs. [Link] 16
hardware/operating system, we have to do this using a compiler and linker. Compiler and linker takes
the source code and creates the executable file that actually runs on the operating system as shown in
Figure For example, if we want to develop an application in C++ programming language, we have to
utilize the compilation/linking process.

Fig. Machine code – hardware relation

The main advantage of native applications is their speed. However, the disadvantage is the
incompatibility across different platforms. For example, we cannot run a native Windows application
on Ubuntu and vice versa. Virtual machine concept is developed to overcome this limitation. Virtual
machine is software that runs on the operating system and provides an abstraction to the developer
as shown in Figure . The application software runs on top of the virtual machine.

Fig. Operating system layer between the hardware and the app

Fig . Creating a native executable from the source code

Therefore, as long as a computer has the virtual machine running, the application software
can run on that computer independent of the hardware and the operating system. A good example is
the Java Virtual Machine (JVM). JVM runs on almost all operating systems and platforms. Therefore,
when we develop Java software, it will be run on the JVM independent of the operating
system/platform. The obvious advantage of developing apps that run on virtual machines can then
be stated as: “develop once and run on all platforms”. However, applications running on virtual
machines are slower than native applications. General development process of virtual machine
applications is summarized in Figure.

Prepared by Mrs. [Link] 17


Fig. Virtual machine between the app and the operating system

Fig . Creating an intermediate code from the source code – intermediate code is interpreted by the virtual
machine

Similar to Java applications, Android applications also run on a JVM. There are two special virtual
machines used in Android: Dalvik Virtual Machine (DVM) and Android Run Time (ART). These
are specialized JVMs which can run on low system resources. The .apk files (executables of Android
apps) actually run on these virtual machines. DVM has been the default runtime environment (~
virtual machine) until the Lollipop release (Android 5.0). ART is introduced by Android 4.0 and has
been the default VM as of Android 5.0. DVM and ART basically do the same job: running Android
apps independent of the platform. The main advantage of ART over DVM is the utilization of a
concept called Ahead of Time (AOT) compilation instead of Just in Time (JIT) approach. In AOT,
apps are compiled during installation hence they load faster with lower CPU usage. On the other
hand, JIT compilation provides lower storage space consumption with relatively longer loading
times.

Prepared by Mrs. [Link] 18


1. The Java source files get compiled to bytecode.
2. An Android application package, or APK file, gets created.
The APK file includes the compiled Java files, along with any libraries and resources needed by
your app.

3. Assuming there’s not one already running, the emulator gets launched with the AVD.
4. Once the emulator has been launched and the AVD is active, the APK file is uploaded to the

AVD and installed.

5. The AVD starts the main activity associated with the app.

Your app gets displayed on the AVD screen, and it’s all ready for you to test out.

Java Development Kit (JDK):


` The Android SDK was developed using the Java programming language. Similarly,
Android applications are also developed using Java. As a result, the Java Development Kit (JDK) is
the first component that must be installed. Android development requires the installation of version
6 or above of the Standard Edition of the Java Platform Development Kit. Java is provided in both
development (JDK) and runtime (JRE) packages.

How Java and Android work together:


After writing a program in Java for Android, we click on a button to change our code into
Prepared by Mrs. [Link] 19
another form that is understood by Android. This other form is called Dalvik EXecutable (DEX)
code, and the transformation process is called compiling.
Compiling takes place on the development machine after we click on that button.
The part of the Android system that executes (runs) our compiled DEX code is called the Dalvik
Virtual Machine (DVM). The DVM itself is a piece of software written in another language that
runs on a specially adapted version of the Linux operating system. So what the user sees of Android,
is itself just an app running on another operating system.
The purpose of the DVM is to hide the complexity and diversity of the hardware and software that
Android runs on but, at the same time, its purpose is to expose all of its useful features. This exposing
of features generally works in two ways. The DVM itself must have access to the hardware, which it
does, but this access must be programmer friendly and easy to use. The way the DVM allows us
access is indeed easy to use because of the Android Application Programming Interface (API).

Android SDK

The Android SDK is a software development kit for Android development that contains the
necessary components to build Android applications. It comes as part of the Android Studio and
includes a comprehensive set of development tools including a debugger, software libraries of
prewritten code, a device emulator to run your Android applications, documentation, sample code,
and tutorials. These tools are used to create apps that look great and take advantage of the
hardware capabilities.
 The Android Virtual Device manager that comes with the Android SDK enables to test
application with any version of Android.

Prepared by Mrs. [Link] 20


 The Android SDK and Gradle tooling incorporate the needed tools to build, compile, and
package Android applications.
 For debugging Android applications, the Android Debug Bridge (adb) tool that enables to
connect to any virtual or real Android device.
Here's the list of the important packages in the Android SDK:
 SDK Tools
 SDK Platform Tools
 SDK Platform
 System Image
 SDK Samples

Android - Developer Tools


The android developer tools are used to create interactive and powerful application for android
platform. The tools can be generally categorized into two types.
 SDK tools
 Platform tools
SDK tools
SDK tools are generally platform independent and are required no matter which android
platform you are working on. When you install the Android SDK into your system, these tools get
automatically installed. The list of SDK tools has been given below −
Sr. No. Tool and description

android
1
This tool lets you manage AVDs, projects, and the installed components of the SDK

ddms
2
This tool lets you debug Android applications

Draw 9-Patch
3
This tool allows you to easily create a NinePatch graphic using a WYSIWYG editor

emulator
4
This tools let you test your applications without using a physical device

mksdcard
5
Helps you create a disk image (external sdcard storage) that you can use with the emulator

proguard
6
Shrinks, optimizes, and obfuscates your code by removing unused code

sqlite3
7
Lets you access the SQLite data files created and used by Android applications

traceview
8
Provides a graphical viewer for execution logs saved by your application

Prepared by Mrs. [Link] 21


Adb
9 Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an
emulator instance or connected Android-powered device.

Android Virtual Device (AVD):


An Android Virtual Device (AVD) is an emulator configuration that allows developers to test
the application by simulating the real device capabilities, without the necessity to install the
application on a physical Android based device. An AVD may be configured to emulate a variety
of hardware features including options such as screen size, memory capacity and the presence or
otherwise of features such as a camera, GPS navigation support or an accelerometer. As part of the
standard Android Studio installation, a number of emulator templates are installed allowing AVDs to
be configured for a range of different devices. Additional templatesmay be loaded or custom
configurations created to match any physical Android device by specifying properties such as
processor type, memory capacity and the size and pixel density of the screen. When launched, an
AVD will appear as a window containing an emulated Android device environment. Figure, for
example, shows an AVD session configured to emulate the Google Nexus 6 API 15 model. New
AVDs are created and managed using the Android Virtual Device Manager, which may be used either
in command-line mode or with a more user-friendly graphical user interface.

Fig. sample AVD

An AVD contains a hardware profile, system image, storage area, skin, and other properties.
AVD and app features
Hardware Profile
Description
Property

Prepared by Mrs. [Link] 22


Device Name Name of the hardware profile. The name can contain uppercase or
lowercase letters, numbers from 0 to 9, periods (.), underscores (_),
parentheses ( () ), and spaces. The name of the file storing the hardware
profile is derived from the hardware profile name.

Device Type Select one of the following:


 Phone/Tablet
 Wear OS
 Android TV
 Chrome OS Device
 Android Automotive

Screen Size The physical size of the screen, in inches, measured at the diagonal. If the
size is larger than your computer screen, it’s reduced in size at launch.

Screen Resolution Type a width and height in pixels to specify the total number of pixels on
the simulated screen.

Round Select this option if the device has a round screen, such as some Wear OS
devices.

Memory: RAM Type a RAM size for the device and select the units, one of B (byte), KB
(kilobyte), MB (megabyte), GB (gigabyte), or TB (terabyte).

Input: Has Select this option if your device has hardware navigation buttons. Deselect
Hardware Buttons it if these buttons are implemented in software only. If you select this
(Back/Home/Menu) option, the buttons won’t appear on the screen. You can use the emulator
side panel to "press" the buttons, in either case.

Input: Has Select this option if your device has a hardware keyboard. Deselect it if it
Hardware Keyboard doesn’t. If you select this option, a keyboard won’t appear on the screen.
You can use your computer keyboard to send keystrokes to the emulator, in
either case.

Navigation Style Select one of the following:


 None - No hardware controls. Navigation is through the software.
 D-pad - Directional Pad support.
 Trackball
 Wheel
These options are for actual hardware controls on the device itself.
However, the events sent to the device by an external controller are the
same.

Supported Device Select one or both options:


States  Portrait - Oriented taller than wide.
 Landscape - Oriented wider than tall.

Prepared by Mrs. [Link] 23


If you select both, you can switch between orientations in the emulator.
You must select at least one option to continue.

Cameras To enable the camera, select one or both options:


 Back-Facing Camera - The lens faces away from the user.
 Front-Facing Camera - The lens faces toward the user.
Later, you can use a webcam or a photo provided by the emulator to
simulate taking a photo with the camera.

Sensors: Select if the device has hardware that helps the device determine its
Accelerometer orientation.

Sensors: Gyroscope Select if the device has hardware that detects rotation or twist. In
combination with an accelerometer, it can provide smoother orientation
detection and support a six-axis orientation system.

Sensors: GPS Select if the device has hardware that supports the Global Positioning
System (GPS) satellite-based navigation system.

Sensors: Proximity Select if the device has hardware that detects if the device is close to your
Sensor face during a phone call to disable input from the screen.

Default Skin Select a skin that controls what the device looks like when displayed in the
emulator. Remember that specifying a screen size that's too big for the
resolution can mean that the screen is cut off, so you can't see the whole
screen.

Android Emulator
Android Emulator is used to run, debug and test the android application. If you don't have the
real device, it can be the best way to run, debug and test the application.
An emulator is an application that supports a virtual device which prototypes, develops and tests the
applications without using a real device. It acts as all hardware and software features of device. It
cannot make a real phone call. It runs a full Android system stack, down to the kernel level. It includes
a set of preinstalled applications (such as the dialer, messenger) which can be accessed from our
applications.
Each AVD is an independent device. It has its own storage and data. In each configuration, an
Android platform is specified which is to be run in the emulator along with the set of hardware
options, emulator skin, etc. when emulator is launched, we specify the AVD configuration that we
want to load. As soon as we launch the emulator with an AVD configuration, it automatically loads
the user data and SD card data from the AVD directory. By default, cache, user data and SD card is
stored in AVD directory. AVD manager manages all the emulators.

Prepared by Mrs. [Link] 24


Figure Relation between AVD Manager, AVD and Emulator

Dalvik Virtual Machine ( DVM):


The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile
devices. It optimizes the virtual machine for memory, battery life and performance.
Dalvik is a purpose built virtual machine designed specifically for android which was developed
by Dan Bornstein and his team. Strictly it was developed for mobile devices. Dalvik virtual machine
uses register based architecture. With this architecture dalvik virtual machine has few advantages
over JAVA virtual machine such as:
1. Dalvik uses its own 16 bit instruction set than java 8 bit stack instructions, which reduce the dalvik
instruction count and raised its interpreter speed.
2. Dalvik use less space, which means an uncompressed .dex file is smaller in size(few bytes) than
compressed java archive file(.jar file).
The Dex compiler converts the class files into the .dex file that run on the Dalvik VM. Multiple class
files are converted into one dex file.
The compiling and packaging process:

Fig. compiling and packaging process

 As shown in figure, the javac tool compiles the java source file into the class file.
 The dx tool takes all the class files of your application and generates a single .dex file. It is
a platform-specific tool.
 The Android Assets Packaging Tool (aapt) handles the packaging process.

Prepared by Mrs. [Link] 25


Role of Dalvik Virtual Machine
In java we write and compile java program using java compiler and run that bytecode on the
java virtual machine. On the other side, In android we still write and compile java source
file(bytecode) on java compiler, but at that point we recompile it once again using dalvik compiler to
dalvik bytecode(dx tool converts java .class file into .dex format) and this dalvik bytecode is then
executed on the dalvik virtual [Link] android Architecture there is DVM above Linux kernel.
Every single application runs as one process and every process has its own instance of [Link]
time user click on app icon then above process will execute.
Key Feature:
 Android dalvik virtual machine is a registered based Virtual machine.
 With using DVM, android device can run multiple instances of VM efficiently.
 Duplicate String and other constants used in multiple class files are included only once in the .dex
Output to conserve space.
 Java byte code is also converted into alternative instruction set used by DVM.
 An uncompressed .dex file is smaller in size as compare to compressed .jar derived from same .class
file.
 The Dalvik executable may be modified again when installed onto the mobile devices.
 DVM was slimmed down to use less space.
 The Dalvik VM executes file in Dalvik executable (.dex) format which is optimized for minimal
memory foot print.
 DVM not only can run multiple VM instances but creation of new VM must be fast as well.

Comparison of Java VM and the Dalvik virtual machine:


DVM (Dalvik Virtual Machine) JVM (Java Virtual Machine)
1. It is Register based which is designed to run 1. It is Stack based.
on low memory.
2. DVM uses its own byte code and runs “.Dex” 2. JVM uses java byte code and runs “.class” file
file. From Android 2.2 SDK Dalvik has got a having JIT (Just In Time).
Just in Time compiler
3. DVM has been designed so that a device can 3. Single instance of JVM is shared with multiple
run multiple instances of the VM efficiently. applications.
Applications are given their own instance.
4. DVM supports Android operating system only. 4. JVM supports multiple operating systems.
5. For DVM very few Re-tools are available. 5. For JVM many Re-tools are available.
6. There is constant pool for every application. 6. It has constant pool for every class.
7. Here the executable is APK. 7. Here the executable is JAR.

Prepared by Mrs. [Link] 26


Steps to install and configure Android Studio and SDK:
The development environment:
A development environment is a term that refers to having everything you need in order to
develop, set up, and be ready to go in one place.
Android Studio is an integrated development environment (IDE) that takes care of all the
complexities of compiling our code and linking with the JDK and the Android API. Once we have
installed the JDK and Android Studio, we can do everything we need inside this application.

Installing the Java Development Kit (JDK)


The Android SDK was developed using the Java programming language. Similarly, Android
applications are also developed using Java. As a result, the Java Development Kit (JDK) is the first
component that must be installed.
Android Studio development requires the installation of version 8 of the Standard Edition of the Java
Platform Development Kit. Java is provided in both development (JDK) and runtime (JRE) packages.
For the purposes of Android development, the JDK must be installed
 Windows JDK Installation
For Windows systems, the JDK may be obtained from Oracle Corporation’s website using the
following URL:
[Link]
1. Assuming that a suitable JDK is not already installed on your system, download version 8 of
the JDK package that matches the destination computer system. Once downloaded, launch
the installation executable and follow the on screen instructions to complete the installation
process.
2. There will be a series of windows that will guide us through the installation process. The
most we have to do is just click on Next to proceed. The following is a screenshot of the first
window that you will see during the installation:

Prepared by Mrs. [Link] 27


3. Now, click on Next and you will see this window:

4. click on the Change button and you will see this window:

5. Browse to the hard drive where you will be installing all of your development tools. Then
simplify the names of the folders in which you will install the JDK to just Java\JDK\.

Prepared by Mrs. [Link] 28


6. After choosing installation location and folder names, click on Next.

7. Click on Next.
8. Next, you will see the window that says 3 Billion Devices Run Java.

9. Now, you will see the final screen.

10. Click on Close, and we are almost done installing the JDK.
11. Now, we will make sure that Windows (and all its applications) know where to find the JDK.
Right-click on your My Computer icon and Properties | Advanced system settings | Environment
Variables |New (under System variables and not under User variables). Now you can see the New
Prepared by Mrs. [Link] 29
System Variable dialog as follows:

12. As shown in the above screenshot, type JAVA_HOME in Variable name and enter D:\Java\JDK
in the Variable value field. If you've installed the JDK somewhere else, then the file path you enter
in the Variable value field will need to point to where you've placed it. Be sure to type it correctly,
make sure that the slashes \ are the right way around, and don't add any extra
slashes.
13. Click on OK to save your new settings. Now, click on OK again to clear the Advanced system
settings window.

Setting up Android Studio:


1. Visit [Link] and click on the Download Android Studio
for Windows button. If at the time of reading this the link has changed, simply Google Download
Android Studio.
2. Next, you will see the Terms and Conditions page as shown in the following screenshot:

3. Click on the “I have read and agree with the above terms and conditions” checkbox as
highlighted in the above screenshot.
4. Now, click on the DOWNLOAD ANDROID STUDIO FOR WINDOWS button. Wait for the
download to complete.
5. Open the folder where you have downloaded Android Studio. Right-click on the android-studio-
[Link] file and select Run as administrator. Your file will most likely
have a different name based on whichever is the current version of Android Studio at the time.
6. When you get the Do you want the following program to be allowed to make changes to this
computer message, click on Yes. You will see the first window of the installation process.
7. Let's step through the setup process a window at a time. Pictured next is the first window that you
will see when you start the setup process:

Prepared by Mrs. [Link] 30


8. Click on Next. Now we can see a few options, as in this next screenshot:

9. Make sure that all the options have a tick next to them, and then click on Next.
10. The next window is the license agreement. Click on “I Agree”. Take a look at the next screenshot
that shows you the Install Locations window:

11. In this step, we want to install the Android Studio IDE and Android SDK to the same hard drive
where we installed the JDK. So you might just be able to click on Next at this point. However, if
you've installed the JDK to another drive, then we need to change the drive and the folders we use at
this step too. This isn't strictly essential, but it can avoid problems for some users.
12. For Android Studio Installation Location, choose the root of the drive where you've installed the
JDK followed by \Android Studio. So in my case, this will be D:\Android Studio. For Android SDK
Installation Location, choose the same hard drive and simply add Android\sdk as the location. So if,

Prepared by Mrs. [Link] 31


like me, you've installed the JDK on D:, then choose D:\Android\sdk. The next screenshot makes this
clear:

13. Click on Next when you have selected your installation locations.
14. Next, you might see the Emulator Setup window as pictured in the next figure. If you do, then
accept the default settings and click on Next; otherwise, you can skip to step 15. Don't worry if you
don't see this screen, it is a minor issue to do with running the Android emulators a bit more smoothly.
Most of the time, you will probably want to use a real device anyway.

15. The next window asks you to choose a start menu folder, just as when we install any new
Windows app. You might want to make a note of this location. Click on Install to accept the default
settings, and Android Studio will begin to install itself and extract the SDK to the appropriate folder
that we selected earlier. This might take some time.
16. When you see the Installation Complete window, click on Next. Now, you will see the following
window:

Prepared by Mrs. [Link] 32


17. Click on Finish to bring up the second to last window of the installation process. Assuming that
this is your first time using Android Studio, click on the “I do not have a previous version of Android
Studio” or “I do not want to import my settings” radio button and click on OK.

18. Now, in the next screenshot, you get to choose the theme that Android Studio will use. If you like
conventional black texts on white background appearance, then choose IntelliJ, and if you want a
cool dark style, choose Darcula. You can alter any of these schemes from within Android Studio if
you change your mind later.

19. Click on Next when you have chosen your theme.


20. Now Android Studio will connect to the Internet and download some of the Android tools that
we will be using soon. Again, this could take a while.
21. When the Downloading Components window has done its work, it will present you with a Finish
button, Click on it.
22. Finally, we are presented with the Welcome to Android Studio screen. This screen, among other
things, allows us to start a new project or open an existing project. Take a look at the next screenshot:

Prepared by Mrs. [Link] 33


Installing Additional Android SDK Packages
The steps performed so far have installed Java, the Android Studio IDE and the current set of
default Android SDK packages. Before proceeding, it is worth taking some time to verify which
packages are installed and to install any missing or updated packages.
This task can be performed using the Android SDK Settings screen, which may be launched from
within the Android Studio tool by selecting the Configure -> SDK Manager Option from within the
Android Studio welcome dialog. Once invoked, the Android SDK screen of the default settings dialog
will appear as shown below

Immediately after installing Android Studio for the first time it is likely that only the latest released
version of the Android SDK has been installed. To install preview or older versions of the Android
SDK simply select the checkboxes corresponding to the versions and click on the Apply button.
It is also possible that updates will be listed as being available for the latest SDK. To access detailed
information about the packages that are available for update, enable the Show Package Details option
located in the lower right hand corner of the screen. This will display information similar to that
shown in Figure
Prepared by Mrs. [Link] 34
The above figure highlights the availability of an update. To install the updates, enable the checkbox
to the left of the item name and click on the Apply button.
In addition to the Android SDK packages, a number of tools are also installed for building Android
applications. To view the currently installed packages and check for updates, remain within the SDK
settings screen and select the SDK Tools tab as shown below

Setting up an Android Studio Development Environment


Within the Android SDK Tools screen, make sure that the following packages are listed as Installed
in the Status column:
 Android SDK Build-tools
 Android SDK Tools
 Android SDK Platform-tools
 Android Support Repository
 Android Support Library
 Google Repository
 Google USB Driver (Windows only)
 Intel x86 Emulator Accelerator (HAXM installer)

Prepared by Mrs. [Link] 35


In the event that any of the above packages are listed as Not Installed or requiring an update, simply
select the checkboxes next to those packages and click on the Apply button to initiate the installation
process.
Once the installation is complete, review the package list and make sure that the selected packages
are now listed as Installed in the Status column. If any are listed as Not installed, make sure they are
selected and click on the Install packages… button again.
An alternative to using the Android SDK settings panel is to access the Standalone SDK Manager
which can be launched using the link in the lower left hand corner of the settings screen. The
Standalone SDK Manager provides a similar list of packages together with options to perform update
and installation tasks:

Installation of Emulators
Emulators are software that mimics the behavior of real devices. When we develop an app,
we obviously won’t have all the possible devices (Android phones, tablets, etc.) available at hand.
Because of this, we run the apps on emulators for testing on various devices. Emulators are also called
as “Android Virtual Devices (AVDs)” in Android Studio. When Android Studio is first installed,
there is no default AVD. We need to create one before testing our apps.
1. For this, select Tools  Android  AVD Manager as shown below

Prepared by Mrs. [Link] 36


2. When AVD Manager appears, there won’t be any AVDs created or installed. Please click on
the Create a Virtual Device button as shown below:

3. AVD Manager will show a detailed window.

4. You can select various devices with different screen sizes and other hardware properties. You
can select device groups from the left pane as TV, Phone, etc. Phone group is the default
selection. In this group, Nexus 5 is also selected by default. When you click “Next”, you’ll be
presented by choices for the Android version of the AVD as shown below.

Prepared by Mrs. [Link] 37


5. The recommended targets start from Android 5.1. We can Android 7.0 with Goole APIs (Nougat)
as shown in the figure. Then, please click “Next” and give a name you like to the AVD.

6. After clicking “Finish”, the AVD is created and shown in the AVD Manager as

7. You can now try your Android apps on this AVD, which will accurately mimic the behaviour
of a real Nexus 5 phone. We can run the AVD by clicking the “Play” button shown inside the
square in above Figure
8. The virtual device will appear as in Figure below which you can use like a real Nexus 5 phone.

Create Your First Android App


The development process
An Android app project begins with an idea and a definition of the requirements necessary to
realize that idea. As the project progresses, it goes through design, development, and testing.
Prepared by Mrs. [Link] 38
The above diagram is a high-level picture of the development process, with the following steps:
Defining the idea and its requirements: Most apps start with an idea of what it should do,
bolstered by market and user research. During this stage the app's requirements are defined.
Prototyping the user interface: Use drawings, mock ups and prototypes to show what the user
interface would look like, and how it would work.
Developing and testing the app: An app consists of one or more activities. For each activity
you can use Android Studio to do the following, in no particular order:
Create the layout: Place UI elements on the screen in a layout, and assign string resources
and menu items, using the Extensible Markup Language (XML).
Write the Java code: Create source code for components and tests, and use testing and
debugging tools.
Register the activity: Declare the activity in the manifest file.
Define the build: Use the default build configuration or create custom builds for different
versions of your app.
Publishing the app: Assemble the final APK (package file) and distribute it through channels
such as the Google Play.

Using Android Studio


Android Studio provides tools for the testing, and publishing phases of the development process,
and a unified development environment for creating apps for all Android devices. The
development environment includes code templates with sample code for common app features,
extensive testing tools and frameworks, and a flexible build system.
Starting an Android Studio project
After you have successfully installed the Android Studio IDE, double-click the Android Studio
application icon to start it. Choose Start a new Android Studio project in the Welcome window,
and name the project the same name that you want to use for the app.
When choosing a unique Company Domain, keep in mind that apps published to the Google Play
must have a unique package name. Since domains are unique, prepending the app's name with
your name, or your company's domain name, should provide an adequately unique package name.
If you are not planning to publish the app, you can accept the default example domain. Be aware
that changing the package name later is extra work.

Choosing target devices and the minimum SDK


When choosing Target Android Devices, Phone and Tablet are selected by default, as shown in the
Prepared by Mrs. [Link] 39
figure below. The choice shown in the figure for the Minimum SDK — API 15: Android 4.0.3
(IceCreamSandwich) — makes your app compatible with 97% of Android devices active on the
Google Play Store.

Different devices run different versions of the Android system, such as Android 4.0.3 or Android
4.4. Each successive version often adds new APIs not available in the previous version. To indicate
which set of APIs are available, each version specifies an API level. For instance, Android 1.0 is
API level 1 and Android 4.0.3 is API level 15.
The Minimum SDK declares the minimum Android version for your app. Each successive version
of Android provides compatibility for apps that were built using the APIs from previous versions,
so your app should always be compatible with future versions of Android while using the
documented Android APIs.

Choosing a template
Android Studio pre-populates your project with minimal code for an activity and a screen layout
based on a template. A variety of templates are available, ranging from a virtually blank template
(Add No Activity) to various types of activities.
You can customize the activity after choosing your template. For example, the Empty Activity
template provides a single activity accompanied by a single layout resource for the screen. You can
choose to accept the commonly used name for the activity (such as MainActivity) or change the
name on the Customize the Activity screen. Also, if you use the Empty Activity template, be sure
to check the following if they are not already checked:
 Generate Layout file: Leave this checked to create the layout resource connected to this
activity, which is usually named activity_main.xml. The layout defines the user interface for
the activity.
 Backwards Compatibility (AppCompat): Leave this checked to include the AppCompat
library so that the app is compatible with previous versions of Android even if it uses features
found only in newer versions.

Prepared by Mrs. [Link] 40


Android Studio creates a folder for the newly created project in the AndroidStudioProjects folder
on your computer.

Android Studio window panes


The Android Studio main window is made up of several logical areas, or panes, as shown in the
figure below.

In the above figure:


1) The [Link] toolbar carries out a wide range of actions, including running the Android app
and launching Android tools.
2) The Navigation Bar. The navigation bar allows navigation through the project and open files
Prepared by Mrs. [Link] 41
for editing. It provides a more compact view of the project structure.
3) The Editor Pane. This pane shows the contents of a selected file in the project. For example,
after selecting a layout (as shown in the figure), this pane shows the layout editor with tools to
edit the layout. After selecting a Java code file, this pane shows the code with tools for editing
the code.
4) The Status Bar. The status bar displays the status of the project and Android Studio itself, as
well as any warnings or messages. You can watch the build progress in the status bar.
5) The Project Pane. The project pane shows the project files and project hierarchy.
6) The Monitor Pane. The monitor pane offers access to the TODO list for managing tasks, the
Android Monitor for monitoring app execution (shown in the figure), the logcat for viewing log
messages, and the Terminal application for performing Terminal activities.
Tip: You can organize the main window to give yourself more screen space by hiding or moving
panes. You can also use keyboard shortcuts to access most features.

Exploring a project
Each project in Android Studio contains the [Link] file, component source-code
files, and associated resource files. By default, Android Studio organizes your project files based
on the file type, and displays them within the Project: Android view in the left tool pane, as
shown below. The view provides quick access to your project's key files.
To switch back to this view from another view, click the vertical Project tab in the far left column
of the Project pane, and choose Android from the pop-up menu at the top of the Project pane, as
shown in the figure below.

In the figure above:


1. The Project tab. Click to show the project view.
2. The Android selection in the project drop-down menu.

Prepared by Mrs. [Link] 42


3. The [Link] file. Used for specifying information about the app for the Android
runtime environment. The template you choose creates this file.
4. The java folder. This folder includes activities, tests, and other components in Java source code.
Every activity, service, and other component is defined as a Java class, usually in its own file. The
name of the first activity (screen) the user sees, which also initializes app-wide resources, is
customarily MainActivity.
5. The res folder. This folder holds resources, such as XML layouts, UI strings, and images. An
activity usually is associated with an XML resource file that specifies the layout of its views. This
file is usually named after its activity or function.
6. The [Link] (Module: App) file. This file specifies the module's build configuration. The
template you choose creates this file, which defines the build configuration, including the
minSdkVersion attribute that declares the minimum version for the app, and the targetSdkVersion
attribute that declares the highest (newest) version for which the app has been optimized. This file
also includes a list of dependencies, which are libraries required by the code — such as the
AppCompat library for supporting a wide range of Android versions.

Viewing the Android Manifest


Before the Android system can start an app component, the system must know that the component
exists by reading the app's [Link] file. The app must declare all its components in this
file, which must be at the root of the app project directory.
To view this file, expand the manifests folder in the Project: Android view, and double-click the file
([Link]). Its contents appear in the editing pane as shown in the figure below.

Android namespace and application tag

The Android Manifest is coded in XML and always uses the Android namespace:

xmlns:android="[Link]
package="[Link]">
The package expression shows the unique package name of the new app. Do not change this once
the app is published.

Prepared by Mrs. [Link] 43


The <application tag, with its closing </application> tag, defines the manifest settings for the
entire app.
<application
...
</application>

Automatic backup
The android:allowBackup attribute enables automatic app data backup:

...
android:allowBackup="true"
...
Setting the android:allowBackup attribute to true enables the app to be backed up automatically and
restored as needed. Users invest time and effort to configure apps. Switching to a new device can
cancel out all that careful configuration. The system performs this automatic backup for nearly all
app data by default, and does so without the developer having to write any additional app code.
For apps whose target SDK version is Android 6.0 (API level 23) and higher, devices running
Android 6.0 and higher automatically create backups of app data to the cloud because the
android:allowBackup attribute defaults to true if omitted. For apps < API level 22 you have to
explicitly add the android:allowBackup attribute and set it to true .

The app icon


The android:icon attribute sets the icon for the app:

...
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
...

The android:icon attribute assigns an icon in the mipmap folder (inside the res folder in Project:
Android view) to the app. The icon appears in the Launcher for launching the app. The icon is
also used as the default icon for app components.

App label and string resources


As you can see in the previous figure, the android:label attribute shows the string "Hello World"
highlighted. If you click on this string, it changes to show the string resource @string/app_name

...
android:label="@string/app_name"
...

Tip: Ctrl-click or right-click app_name in the edit pane to see the context menu. Choose Go To >
Declaration to see where the string resource is declared: in the [Link] file. When you choose
Go To > Declaration or open the file by double- clicking [Link] in the Project: Android view
(inside the values folder), its contents appear in the editing pane.
Prepared by Mrs. [Link] 44
After opening the [Link] file, you can see that the string name app_name is set to Hello
World You can change the app name by changing the Hello World string to something else.
String resources are described in a separate lesson.

The app theme


The android:theme attribute sets the app's theme, which defines the appearance of user interface
elements such as text:
...
android:theme="@style/AppTheme">
...

The theme attribute is set to the standard theme AppTheme .

Declaring the Android version


Different devices may run different versions of the Android system, such as Android 4.0 or Android
4.4. Each successive version can add new APIs not available in the previous version. To indicate
which set of APIs are available, each version specifies an API level. For instance, Android 1.0 is
API level 1 and Android 4.4 is API level 19.
The API level allows a developer to declare the minimum version with which the app is compatible,
using the <uses-sdk> manifest tag and its minSdkVersion attribute. For example, the Calendar
Provider APIs were added in Android 4.0 (API level 14). If your app can't function without these
APIs, declare API level 14 as the app's minimum supported version like this:

<manifest ... >


<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
...
</manifest>

The minSdkVersion attribute declares the minimum version for the app, and the targetSdkVersion
attribute declares the highest (newest) version which has been optimized within the app. Each
successive version of Android provides compatibility for apps that were built using the APIs from
previous versions, so the app should always be compatible with future versions of Android while
using the documented Android APIs.
The targetSdkVersion attribute does not prevent an app from being installed on Android versions
that are higher (newer) than the specified value, but it is important because it indicates to the system
whether the app should inherit behavior changes in newer versions. If you don't update the
targetSdkVersion to the latest version, the system assumes that your app requires some backward-
compatibility behaviors when running on the latest version. For example, among the behavior
changes in Android 4.4, alarms created with the AlarmManager APIs are now inexact by default so
that the system can batch app alarms and preserve system power, but the system will retain the
previous API behavior for an app if your target API level is lower than "19" .

Viewing and editing Java code


Components are written in Java and listed within module folders in the java folder in the Project:
Android view. Each module name begins with the domain name (such as [Link])
Prepared by Mrs. [Link] 45
and includes the app name.
The following example shows an activity component:
1. Click the module folder to expand it and show the MainActivity file for the activity written in
Java (the MainActivity
class).
2. Double-click MainActivity to see the source file in the editing pane, as shown in the figure
below.

At the very top of the [Link] file is a package statement that defines the app package.
This is followed by an import block condensed in the above figure, with " ". Click the dots
to expand the block to view it. The import statements import libraries needed for the app, such as
the following, which imports the AppCompatActivity library:

import [Link];

Each activity in an app is implemented as a Java class. The following class declaration extends the
AppCompatActivity class to implement features in a way that is backward-compatible with previous
versions of Android:

public class MainActivity extends AppCompatActivity {


...
}
As you learned earlier, before the Android system can start an app component such as an activity,
the system must know that the activity exists by reading the app's [Link] file.
Therefore, each activity must be listed in the [Link] file.

Viewing and editing layouts


Layout resources are written in XML and listed within the layout folder in the res folder in the
Project: Android view. Click res > layout and then double-click activity_main.xml to see the layout
file in the editing pane.
Android Studio shows the Design view of the layout, as shown in the figure below. This view
provides a Palette pane of user interface elements, and a grid showing the screen layout.

Prepared by Mrs. [Link] 46


Understanding the build process
The Android application package (APK) is the package file format for distributing and installing
Android mobile apps. The build process involves tools and processes that automatically convert
each project into an APK.
Android Studio uses Gradle as the foundation of the build system, with more Android-specific
capabilities provided by the Android Plugin for Gradle. This build system runs as an integrated tool
from the Android Studio menu.

Understanding [Link] files

When you create a project, Android Studio automatically generates the necessary build files in the
Gradle Scripts folder in Project: Android view. Android Studio build files are named [Link]
as shown below:

Each project has the following:

Prepared by Mrs. [Link] 47


[Link] (Project: apptitle)
This is the top-level build file for the entire project, located in the root project directory, which
defines build configurations that apply to all modules in your project. This file, generated by
Android Studio, should not be edited to include app dependencies.

[Link] (Module: app)


Android Studio creates separate [Link] (Module: app) files for each module. You can
edit the build settings to provide custom packaging options for each module, such as
additional build types and product flavors, and to override settings in the manifest or top-level
[Link] file. This file is most often the file to edit when changing app-level

apply plugin: '[Link]'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId
"[Link].helloworld2"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "[Link]"
}
buildTypes {
release {
minifyEnabled false
configurations, such asgetDefaultProguardFile('[Link]'),
proguardFiles declaring dependencies in the dependencies section. The following
'[Link]'
shows} the contents of a project's [Link] (Module: app) file:

}
The [Link] files use Gradle syntax. Gradle is a Domain Specific Language (DSL) for
} describing and manipulating the build logic using Groovy, which is a dynamic language for the
Java Virtual Machine (JVM). You don't need to learn Groovy to make changes, because the
Android Plugin
dependencies { for Gradle introduces most of the DSL elements you need.
Tip: To learn more
compile about the Android
fileTree(dir: 'libs', plugin DSL, read ['*.jar'])
include: the DSL reference documentation.
androidTestCompile('[Link]:espresso
-core:2.2.2', {
exclude group: '[Link]', module: 'support-annotations'
})
compile '[Link]:appcompat-
v7:24.2.1' testCompile 'junit:junit:4.12'
}
Prepared by Mrs. [Link] 48
Plugin and Android blocks
In the above [Link] (Module: app) file, the first statement applies the Android-specific Gradle
plug-in build tasks:

apply plugin: '[Link]'

android
{
...
}
The android { } block specifies the following for the build:

The target SDK version for compiling the code:

compileSdkVersion 24

The version of the build tools to use for building the app:
buildToolsVersion "24.0.1"

The defaultConfig block

Core settings and entries for the app are specified in a defaultConfig { } block within the android { } block:

...
defaultConfig {
applicationId
"[Link]"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner
"[Link]
"
}
...

The minSdkVersion and targetSdkVersion settings override any [Link] settings for
the minimum SDK version and the target SDK version. See "Declaring the Android version"
previously in this chapter for background information on these settings.
The testInstrumentationRunner statement adds the instrumentation support for testing the user
interface with Espresso and UIAutomator. These are described in a separate lesson.
Build types

Build types for the app are specified in a buildTypes { } block, which controls how the app is built
and packaged.

Prepared by Mrs. [Link] 49


...
buildTypes {
release {
minifyEnabled false
proguardFiles
getDefaultProguardFile('[Link]'),
'[Link]'
}
}
...

The build type specified is release for the app's release. Another common build type is debug .

Dependencies

Dependencies for the app are defined in the dependencies { } block, which is the part of the
[Link] file that is most likely to change as you start developing code that depends on other
libraries. The block is part of the standard Gradle API and belongs outside the android { } block.
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('[Link]:espr
esso-core:2.2.2', {
exclude group: '[Link]', module: 'support-annotations'
})
compile '[Link]:appcompat-
v7:24.2.0' testCompile
'junit:junit:4.12'
}

In the above snippet, the statement compile fileTree(dir: 'libs', include: ['*.jar']) adds a dependency
of all ".jar" files inside the libs directory. The compile configuration compiles the main application
— everything in it is added to the compilation class path, and also packaged into the final APK.

Syncing your project

When you make changes to the build configuration files in a project, Android Studio requires that
you sync the project files so that it can import the build configuration changes and run some checks
to make sure the configuration won't create build errors.
To sync the project files, click Sync Now in the notification bar that appears when making a change,
or click Sync Project from the menu bar. If Android Studio notices any errors with the configuration
— for example, if the source code uses API features that are only available in an API level higher
than the compileSdkVersion — the Messages window appears to describe the issue.

Prepared by Mrs. [Link] 50


Running the app on an emulator or a device
With virtual device emulators, you can test an app on different devices such as tablets or
smartphones — with different API levels for different Android versions — to make sure it looks
good and works for most users. Although it's a good idea, you don't have to depend on having a
physical device available for app development.
The Android Virtual Device (AVD) manager creates a virtual device or emulator that simulates the
configuration for a particular type of Android device. Use the AVD Manager to define the hardware
characteristics of a device and its API level, and to save it as a virtual device configuration. When
you start the Android emulator, it reads a specified configuration and creates an emulated device on
your computer that behaves exactly like a physical version of that device.

Creating a virtual device

To run an emulator on your computer, use the AVD Manager to create a configuration that describes
the virtual device. Select Tools > Android > AVD Manager, or click the AVD Manager icon in the
toolbar.
The "Your Virtual Devices" screen appears showing all of the virtual devices created previously.
Click the +Create Virtual Device button to create a new virtual device.

You can select a device from a list of predefined hardware devices. For each device, the table shows
its diagonal display size (Size), screen resolution in pixels (Resolution), and pixel density (Density).
For example, the pixel density of the Nexus 5 device is xxhdpi , which means the app uses the
icons in the xxhdpi folder of the mipmap folder. Likewise, the app will use layouts and drawables
from folders defined for that density as well.
Prepared by Mrs. [Link] 51
You also choose the version of the Android system for the device. The Recommended tab shows
the recommended systems for the device. More versions are available under the x86 Images and
Other Images tabs.
Running the app on the virtual device

To run the app on the virtual device you created in the previous section, follow these steps:
[Link] Android Studio, select Run > Run app or click the Run icon in the toolbar.
2. In the Select Deployment Target window, under Available Emulators, select the virtual device
you created, and click OK.
The emulator starts and boots just like a physical device. Depending on the speed of your
computer, this may take a while. The app builds, and once the emulator is ready, Android Studio
uploads the app to the emulator and runs it.
You should see the app created from the Empty Activity template ("Hello World") as shown in
the following figure, which also shows Android Studio's Run pane that displays the actions
performed to run the app on the emulator.
Note: When testing on an emulator, it is good practice to start it up once at the very beginning
of your session, and not to close it until done so that it doesn't have to go through the boot process
again.

Prepared by Mrs. [Link] 52


In the above figure:
1. The Emulator running the app.
2. The Run Pane. This shows the actions taken to install and run the app.

Running the app on a physical device


Always test your apps on physical device, because users will use the app on physical devices.
While emulators are quite good, they can't show all possible device states, such as what happens
if an incoming call occurs while the app is running. To run the app on a physical device, you
need the following:
An Android device such as a smartphone or tablet.
A data cable to connect the Android device to your computer via the USB port.
If you are using Linux or Windows, it may be necessary to perform additional steps to run the
app on a hardware device. Check the Using Hardware Devices documentation. On Windows,
you may need to install the appropriate USB driver for the device. See OEM USB Drivers.
To let Android Studio communicate with a device, turn on USB Debugging on the Android
device. On Android version 4.2 and newer, the Developer options screen is hidden by default.
Follow these steps to turn on USB Debugging:
1. On the physical device, open Settings and choose About phone at the bottom of the Settings
screen.
2. Tap the Build number information seven times.
You read that correctly: Tap it seven times.
3. Return to the previous screen (Settings). Developer options now appears at the bottom of the
screen. Tap
Developer options.
4. Choose USB Debugging.
Now, connect the device and run the app from Android Studio.

Troubleshooting the device connection


Prepared by Mrs. [Link] 53
If Android Studio does not recognize the device, try the following:
1. Disconnect the device from your computer, and then reconnect it.
2. Restart Android Studio.
3. If your computer still does not find the device or declares it "unauthorized":
i. Disconnect the device from your computer.
ii. On the device, choose Settings > Developer Options.
iii. Tap Revoke USB Debugging authorizations.
iv. Reconnect the device to your computer.
v. When prompted, grant authorizations.
4. You may need to install the appropriate USB driver for the device. See Using Hardware Devices
documentation.
5. Check the latest documentation, programming forums, or get help from your instructors.

Using the log


The log is a powerful debugging tool you can use to look at values, execution paths, and
exceptions. After you add logging statements to an app, your log messages appear along with
general log messages in the logcat tab of the Android Monitor pane of Android Studio.
To see the Android Monitor pane, click the Android Monitor button at the bottom of the Android
Studio main window. The Android Monitor offers two tabs:
The logcat tab. The logcat tab displays log messages about the app as it is running. If you
add logging statements to the app, your log messages from these statements appear with the
other log messages under this tab.
The Monitors tab. The Monitors tab monitors the performance of the app, which can be
helpful for debugging and tuning your code.

Adding logging statements to your app

Logging statements add whatever messages you specify to the log. Adding logging statements at
certain points in the code allows the developer to look at values, execution paths, and exceptions.
For example, the following logging statement adds "MainActivity" and "Hello World" to the log:

Log.d("MainActivity", "Hello World");

The following are the elements of this statement:

Log : The Log class is the API for sending log messages.
d : You assign a log level so that you can filter the log messages using the drop-down menu in
the center of the
logcat tab pane. The following are log levels you can assign:
d : Choose Debug or Verbose to see these messages.
e : Choose Error or Verbose to see these messages.
w : Choose Warning or Verbose to see these messages.
i : Choose Info or Verbose to see these messages.
"MainActivity" : The first argument is a log tag which can be used to filter messages under
the logcat tab. This is commonly the name of the activity from which the message originates.
However, you can make this anything that is useful to you for debugging the app. The best
Prepared by Mrs. [Link] 54
practice is to use a constant as a log tag, as follows:
1. Define the log tag as a constant before using it in logging statement:
private static final String LOG_TAG =
[Link]();

2. Use the constant in the logging statements:


Log.d(LOG_TAG, "Hello World");

3. "Hello World" : The second argument is the actual message that appears after the log level
and log tag under the logcat tab.

Viewing your log messages


The Run pane appears in place of the Android Monitor pane when you run the app on an emulator
or a device. After starting to run the app, click the Android Monitor button at the bottom of the
main window, and then click the logcat tab in the Android Monitor pane if it is not already
selected.

In the above figure:


1. The logging statement in the onCreate() method of MainActivity .
2. Android Monitor pane showing logcat log messages, including the message from the logging
statement.
By default, the log display is set to Verbose in the drop-down menu at the top of the logcat
display to show all messages. You can change this to Debug to see messages that start with
Log.d , or change it to Error to see messages that start with Log.e , and so on.

Prepared by Mrs. [Link] 55

You might also like