Chapter 1-Introduction To Android Platform
Chapter 1-Introduction To Android Platform
Computer Engineering
DJIONGO Cedrigue
djiongocedrigue@gmail.com
© 2020
University of Bamenda / College of Technology
Computer Engineering
Master 1
Academic Year: 2019-2020
Syllabus:
Mobile Application Development
Code and Course Title: Mobile Application Development
Credits: 3
Hour charge: 30h (CM = 20; TD /TP= 5; TI = 5)
Teacher: DJIONGO KENFACK Cedrigue Boris, +237 697121054,
djiongocedrigue@gmail.com
Availability: End of the week / August, September, May
Assistant (chargé de TD / TP) :
Prerequisite:
Keywords : mobile apps, constrained resources, sensors, security, Android, Google
Play Store
Software : Visual Studio Code, Android SDK
Objectives :
This course introduces students to programming technologies, design and development
related to mobile applications. Topics include accessing device capabilities, industry standards,
operating systems and programming for mobile applications using OS Software Development
Kit (SDK). This project oriented course will investigate application development for the
Android mobile Platform. We will look at the techniques for building applications that adapt to
the ways in which mobile apps differ from traditional desktop ar web-based apps, including
constrained resources, small screen sizes, varying display resolutions, intermittent network
connectivity, specialized sensors and security restrictions.
Upon completion, students should be able to:
(1) Create basic applications for mobile devices, debug and test a mobile application,
(2) Apply layout management and multi-layout definition techniques to create adaptable user
interfaces for mobile applications that share a common data model, (3) Manage user data and
multimedia on a mobile device via the Android framework libraries, (4) Use the sensors
available on mobile devices to enhance user interaction and feedback, and (5) Publish
application to the Google Play Store.
1 / 19
Bibliography :
[Späth2018] Peter Späth, Pro Android with Kotlin: Developing Modern Mobile Apps,
ISBN: 978-1-4842-3820-2, Apress, 2018
[Wickham2018] Mark Wickham, Practical Android: 14 Complete Projects on
Advanced Techniques and Approaches, ISBN: 978-1-4842-3333-7, Apress, 2018
[Jackson2017] Wallace Jackson Android Apps for Absolute Beginners: Covering
Android 7, 4th Ed. ISBN:978-1-4842-2268-3, Apress, 2017
[DiMarzio2017] J. F. DiMarzio, Beginning Android® Programming with Android
Studio, ISBN: 978-1-119-19609-9, John Wiley & Sons, 2017
2 / 19
Chapter 1 Introduction to Android Platform
The Android OS was originally created by Andy Rubin to be an OS for mobile phones.
It was born as the child of the Android Inc. company in 2003 and was later acquired by Google
LLC in 2005 as part of its strategy to enter the mobile space. Google wanted the Android OS
to be open and free, so most of the Android code was released under the open source Apache
License. Moreover, vendors (typically hardware manufacturers) can add their own proprietary
extensions to Android and customize Android to differentiate their products from others.
However, the Nexus devices always run a clean version of Android with no modifications.
The first device running Android came on the market in 2008. Since then it has had
numerous updates, with the latest version number at the beginning of 2018 reading 8.1. Ever
since its first build, the market share of the Android OS has been constantly increasing, and by
2018 it is said to be greater than 80 percent. The Android OS is tailor to match the needs of
smartphones and other handheld or handheld-like devices. Android devices come in all shapes
and sizes including, but not limited to, the following types of devices: Smartphones, Tablets,
E-reader devices, Internet TVs, Automobiles, and Smartwatches.
A Compatibility Definition Document (CDD) and Compatibility Test Suite (CTS) that
describe the capabilities required for a device to support the Android software stack.
A Linux operating system kernel that provides a low-level interface with the hardware,
memory management, and process control, all optimized for mobile and embedded
devices.
3 / 19
Open source libraries for application development, including SQLite, WebKit,
OpenGL, and a media manager.
A run time used to execute and host Android applications, including the Android Run
Time (ART) and the core libraries that provide Android-specific functionality. The run
time is designed to be small and efficient for use on embedded devices.
An application framework that agnostically exposes system services to the application
layer, including the Window Manager and Location Manager, databases, telephony, and
sensors.
A user interface framework used to host and launch applications.
A set of core preinstalled applications.
A software development kit (SDK) used to create applications, including the related
tools, IDE, sample code, and documentation.
4 / 19
Android’s web browser is based on the open source WebKit and Chrome’s V8
JavaScript engine.
1. Linux kernel: This is the kernel on which Android is based. This layer contains all the
low-level device drivers for the various hardware components of an Android device.
2. Libraries: These contain the code that provides the main features of an Android OS.
For example, the SQLite library provides database support so that an application can
use it for data storage. The WebKit library provides functionalities for web browsing.
3. Android runtime: The Android runtime is located in the same layer with the libraries
and provides a set of core libraries that enable developers to write Android apps using
the Java programming language. The Android runtime also includes the Dalvik virtual
machine, which enables every Android application to run in its own process, with its
own instance of the Dalvik virtual machine. (Android applications are compiled into
Dalvik executables). Dalvik is a specialized virtual machine designed specifically for
Android and optimized for battery-powered mobile devices with limited memory and
CPU power.
4. Application framework: The application framework exposes the various capabilities
of the Android OS to application developers so that they can make use of them in their
applications.
5. Applications: At this top layer are the applications that ship with the Android device
(such as Phone, Contacts, Browser, and so on), as well as applications that you
5 / 19
download and install from the Google Play Store. Any applications that you write are
located at this layer.
6 / 19
1.2.1 Integrated Development Environment
The first and most important piece of software you need to download is Android Studio.
After you have downloaded and installed Android Studio, you can use the SDK Manager to
download and install multiple versions of the Android SDK. Having multiple versions of the
SDK available enables you to write programs that target different devices. For example, you
can write one version of an application that specifically targets the latest Android OS under
development, but because that flavor of Android is on less than 1% of devices, with multiple
versions of the SDK you can also write a version of your app that uses older features and targets
older Android OS. You can download Android Studio from:
http://developer.android.com/sdk/index.html
The Android SDK includes everything you need to start developing, testing, and
debugging Android applications:
The Android API Libraries: The core of the SDK is the Android API libraries that
provide developer access to the Android stack. These are the same libraries that Google
uses to create native Android applications.
Development tools: The SDK includes the Android Studio IDE and several other
development tools that let you compile and debug your applications to turn Android
source code into executable applications.
The Android Virtual Device Manager and Emulator: The Android Emulator is a
fully interactive mobile device emulator featuring several alternative skins. The
Emulator runs within an Android Virtual Device (AVD) that simulates a device
hardware configuration. Using the Emulator you can see how your applications will
look and behave on a real Android device. All Android applications run within ART, so
7 / 19
the software emulator is an excellent development environment, in fact, because it’s
hardware-neutral, it provides a better independent test environment than any single
hardware implementation.
Full documentation: The SDK includes extensive code-level reference information
detailing exactly what’s included in each package and class and how to use them.
Sample code: The Android SDK includes a selection of sample applications that
demonstrate some of the possibilities available with Android, as well as simple
programs that highlight how to use individual API features.
Online support: Android has vibrant developer communities on most online social
networks, Slack, and many developer forums. Many Android engineers from Google
are active on Stack Overflow and Twitter.
You also need to download and install the Java SDK compatible with your Android
Studio.
The Emulator enables you to see how your application will look, behave, and interact,
but to actually see what’s happening under the surface, you need the Android Profiler. The
Android Profiler displays real-time profiling data for the CPU, memory, and network activity
related to your app. You can perform sample-based method tracing to time your code execution,
capture heap dumps, view memory allocations, and inspect the details of network-transmitted
files. The Profiler window displays real-time graphs for CPU, memory, and network usage, as
well as an event timeline that indicates changes in Activity state, user inputs, and screen
rotations.
8 / 19
1.2.4 Android Debug Bridge
The Android Debug Bridge (ADB) is a client-service application that lets you connect
with an Android device (virtual or actual). It’s made up of three components:
1.2.5 Gradle
Gradle is an advanced build system and toolkit, which makes it possible for you to
perform custom build configurations without needing to modify your app’s source files. The
use of Gradle as Android’s build system is intended to make it easier to configure, extend and
customize the build process, simplify code and resource reuse, and to more easily create
multiple build variants of an application.
The output of the build is the same whether you are building a project from the command line,
on a remote machine, or using an IDE.
9 / 19
arrays, logic loops, and method calls. XML markup is contained in simple text format files
identified using the .xml file extension.
Some examples of advanced Android design-related features that you can implement
primarily using XML markup “definitions” include multi-state graphics, skinned UI elements
(custom graphic design User Interface elements), frame or bitmap image animation, vector or
“tween” (procedural) animation, user interface layout design animation (UI property animator),
options menus, pop-up menus, and context-sensitive menus, dialog boxes, alert dialogs, styles,
themes, and your application’s manifest. You can also implement less advanced, strategic
design features using XML, including string (text) constant values for your app, integer
(numeric) value constants, state or status (Boolean) value constants, and screen spacing
(dimension) values for your UI designs. Arrays, which are collections of data used in your app
(like a simple database), can also be created, and loaded with their data values, by using XML
files.
XML tags and parameters that you can use in any particular design framework are
specified by using an XML “naming schema.” This definition of the XML tags and their
parameters are stored in a centralized repository. The SDK repository hosts the latest Android
SDK versions and code base, whereas the Android XML repository is located at a different
URL location (a different folder) on Google’s Android OS servers. The reason XML needs to
have a naming schema is because this language is inherently designed to be “extensible.” The
process of making sure that XML tags and their attributes or parameters are correct, or valid
and in conformance with their XML definition, is called XML validation.
Android XML has been specifically customized for, and implemented for, the
development of Android applications. Android Studio does not need to validate the XML file
in “real time”, so you do not need an active Internet connection to be able to develop the XML
markup. The following lines of XML markup declare XML and the XML naming schema,
10 / 19
abbreviated as XMLNS, as well as configuring the ConstraintLayout Java class characteristics
using attributes or parameters inside of the parent <ConstraintLayout> tag.
This parent layout container tag will usually contain other child tags, which are nested
inside of, and underneath, the opening parent tag. This nesting of child tags, as well as nesting
parameters inside of the tag, can more easily seen if the XML programmer uses indenting to
show which tags are inside of other higher-level (parent) tags.
Any tag that you will use as a parent tag will have an opening tag; in this case that is the
<ConstraintLayout> tag, and its paired closing tag </ConstraintLayout> with the tag name in
both the opening and the closing tag. The closing tag will have a slash in front of the tag name
to signify to the XML parsing engine (the code that is interpreting the XML markup and turning
it into Java objects, data constants, and data variables) that this is the closing tag. Alternatively,
the child tag that has no children of its own will have the closing slash at the end of the opening
tag. Once you put parameters inside of the parent and child tags, and indent everything, so that
you know what level each of these tags and its parameters are supposed to be ( see code below).
11 / 19
1.3.4 XML Referencing: Chain XML Constructs
Together
XML files can also reference other XML files, so that you can create a chain where
XML definitions can be modular, since they can be blocks of code that can be used by more
than one XML construct. XML file referencing is somewhat akin to XML tag nesting, but it
spans across files. XML referencing in Android is done by using an @ symbol, which is specific
to Android XML file referencing syntax.
Android uses the @ character to signify that another XML file is being referenced to
define values, dimensions, strings, styles, themes, and your Android Manifest, which defines
everything regarding your application. Without this referencing capability XML markup would
end up being all lumped together in one or two massive files. Referencing allows an XML
structure to be created.
12 / 19
1.4 Programming with Java
The programming language used for developing your Android applications is Oracle’s
Java SE, which was created by Sun Microsystems and later acquired by Oracle. Java SE stands
for Java Standard Edition, though many programmers shorten this to just “Java.” Java is what
is called an object-oriented programming (OOP) language.
Data fields that hold a Java object’s states that can change over time are called
variables.
Data fields that hold an object’s states that do not change over time are called constants.
Methods are programming logic or program code routines that operate on, and will
change, the object’s internal variable data fields. Methods will also allow other Java
objects that are external to the object itself to communicate with that object, as long as
the method is declared to be public.
13 / 19
One of the key concepts of OOP is data encapsulation. In Java, data encapsulation is
implemented by only allowing a Java object’s variable data fields to be modified directly
through that same Java object’s internal methods. This allows a Java object to be self-sufficient,
or encapsulated. Using data encapsulation, you can individually build and test each object that
is part of a larger object construct, without requiring any data to be accessed from other objects,
or modules, of an application. External data access can translate into bugs, so encapsulation
helps when developing complicated, large-scale applications. Its also promotes the core
concept in OOP of modularity. Once an object is created and tested, other objects can use it
without worrying about its integrity. Data encapsulation thus allows code reuse, so
programmers can develop libraries of useful objects, which don’t need to be rewritten or
retested by other programmers. Finally, Java objects make debugging easier, because you can
add or remove them modularly, or isolate them during testing in order to ascertain where bugs
are located within the overall code.
To create a class, you use the Java keyword class, followed by a custom name for the
new class you are writing, and then curly brackets, which will eventually contain Java code for
a class definition. For a car class, it looks like this:
The first thing that you will usually put inside of the class (inside of the curly {}
brackets) are the data fields (variables).
To define a variable in Java, you must first declare its data type:
An integer or int data type declares a variable to be able to hold a whole (non-fractional)
number.
14 / 19
A String data type declares the variable to hold a text value.
A Boolean data type declares the variable to hold a true or false value (I think of this
like a switch or a toggle, like a binary on or off state).
The next portion of the variable definition or declaration after the data type has been
specified is your custom variable name, which you will use to refer to that variable later on,
within your Java programming logic. The variable definition is ended once it reaches a
semicolon character.
b- Java Method
A Java method will define how your object will function; that is, how it will operate
on the variables that you defined at the top of the class. Method calls can invoke a variable
(state) change, and methods can also return data values to the entity that calls or invokes the
method, such as data values that have been successfully changed, or even the result of an
equation.
c- Construct method
If you want to be able to make an object with preset values out of your class definition,
then you need to include what is called a constructor method. If you don’t, Java will create
one for you called a default constructor. This method will need to be named the same as the
class name, and should be the first method that is defined inside of the class construct, after the
data field definitions. The constructor method is used to construct an object, configure it, and
load it into memory for use. If all objects that are created using the class need to have the same
starting variables, you can include these in the class instead of the constructor.
The Java constructor method differs from a regular Java method in a number of distinct
ways. First of all, a constructor method does not use any of the data return types, such as
void and int, because it is used to create a Java object, rather than to perform some function. It
does not return nothing or a number, but rather, it returns an object. Another difference between
a constructor and a standard method is constructors must use the public access control modifier,
and cannot use any non-access-control modifiers, so be sure not to declare your constructor as:
static, final, abstract, or synchronized.
d- Java Inheritance
There is also support in Java for developing different variations on custom objects. This
is done using a technique called inheritance. Inheritance is where more specialized classes can
be subclassed using the basic superclass. This allows Java developers to develop more
15 / 19
organized, modular, inheritance-oriented approaches to designing their Java objects, making
them into building blocks, and thus powerful for the construction of an infinite number of future
object types.
To create a subclass using a superclass, you extend the subclass from the superclass, by
using the Java extends keyword inside of the class declaration. To refer to one of the
superclass’s methods from within the subclass you are coding, you can use the Java super
keyword.
e- Java Interfaces
In many Java applications, Java classes must conform to a certain usage pattern. There
is a specialized Java construct called an interface that you can implement, so that other
application developers will know exactly how to utilize your Java classes implementing an
interface, as well as which methods are required for proper implementation of your Java class.
Implementing the Java interface will allow your class to become more conformant regarding
those behaviors that your class offers for other programmers to utilize.
To implement a Java interface, you would use the Java implements keyword, as you
will see later on during this section. Interfaces in essence form a programming contract
between your class and the rest of the development world. For any class implementing a Java
interface, the Java compiler can enforce this contract at build time. If a class claims to
implement a public interface using the implements keyword, all of the methods that are defined
by that Java interface definition must be implemented in the source code for the class that
implements that interface before that class will successfully compile.
16 / 19
g- Java Access Modifiers: Four Levels of Access
Java has a number of modifiers that you can place before Java constructs, to define what
they are and who can see them. There are two types of Java modifiers: access control modifiers
and non-access control modifiers. You can apply access control modifiers to classes, methods,
interfaces, constructors, constants, and variables, and include the public, private, and protected
Java access modifier keywords. Not using any access control keyword at all also defines the
package protected level of access control.
There are also modifiers in Java that are not access control modifiers, and not data type
declarations. These are called non-access modifiers and these are the most complicated ones
to understand and to implement in practical usage. There are three modifiers that are frequently
used in Java programming: a static modifier, a final modifier, and an abstract modifier. There
are also some more advanced modifiers such as synchronized or volatile.
A static modifier keyword when used in conjunction with a variable will create a
variable that will exist independently of any object instances created using that class. Static
variables will be initialized only one time, at the start of the execution of the application,
sometimes called the app launch. The variables that use the static modifier keyword will be
initialized first, before the initialization of any instance variables. Only one copy of a static
variable will exist in system memory regardless of the number of instances of the class that
contains that variable are created.
You can define a class using the final modifier keyword, and if a class is designated
final, it cannot be subclassed. This is usually implemented for reasons of Java security, so
tested, mission-critical Java code cannot be modified or changed. You will notice as we get
deeper into the Android API and Java that many standard Android Java-based library classes
are declared using the final modifier keyword. All methods in a final class are implicitly final
methods. Any method declared using the final modifier keyword cannot be overridden by
subclasses.
17 / 19
A class declared using an abstract modifier keyword can never be instantiated, or
placed into memory as an object and actually utilized in the functionality of an Android (or
Java/ JavaFX) application. If your class is declared as abstract, then the sole purpose for that
class is to be extended, that is, subclassed. If a class contains any methods that have been
declared using the abstract modifier, then the class should also be declared using the abstract
modifier.
The students should be organized in groups of 4 members each and will propose an
Android Application to be develop though the course. Each group is ask to identify a problem
in their environment and propose an Android app to handle this issue.
We will use Visual Studio Code with Android extensions and tools as the alternative to
Android Studio IDE.
1.6 Exercises
1. What is an AVD?
2. Why was Jelly Bean selected for you by default in the Targeted Android Devices dialog?
3. What does SDK stand for?
4. What tool is used to download new Android SDKs?
5. As an exercise, you should practice identifying different objects in the room or space around
you, and then break down their definition or description into various states as well as
behaviors
18 / 19
19 / 19