Uploaded by baby5me

chepter 1

advertisement
Introduction to Android
Ro
mi
l
To
ma
r
Android operating system is the largest installed base among various mobile platforms across
the globe. Hundreds of millions of mobile devices are powered by Android in more than 190
countries of the world. It conquered around 71% of the global market share by the end of 2021,
and this trend is growing bigger every other day. The company named Open Handset Alliance
developed Android for the first time that is based on the modified version of the Linux kernel and
other open-source software. Google sponsored the project at initial stages and in the year 2005,
it acquired the whole company. In September 2008, the first Android-powered device was
launched in the market. Android dominates the mobile OS industry because of the long list of
features it provides. It’s user-friendly, has huge community support, provides a greater extent of
customization, and a large number of companies build Android-compatible smartphones. As a
result, the market observes a sharp increase in the demand for developing Android mobile
applications, and with that companies need smart developers with the right skill set. At first, the
purpose of Android was thought of as a mobile operating system. However, with the
advancement of code libraries and its popularity among developers of the divergent domain,
Android becomes an absolute set of software for all devices like tablets, wearables, set-top
boxes, smart TVs, notebooks, etc.
Features of Android:
Android is a powerful open-source operating system that open-source provides immense
features and some of these are listed below.
●
●
●
●
●
●
●
●
●
●
Ro
mi
l
●
Android Open Source Project so we can customize the OS based on our requirements.
Android supports different types of connectivity for GSM, CDMA, Wi-Fi, Bluetooth, etc.
for telephonic conversation or data transfer.
Using wifi technology we can pair with other devices while playing games or using other
applications.
It contains multiple APIs to support location-tracking services such as GPS.
We can manage all data storage-related activities by using the file manager.
We can perform all data storage related activities by using lightweight database SQLite.
It contains a wide range of media supports like AVI, MKV, FLV, MPEG4, etc. to play or
record a variety of audio/video.
It also supports different image formats like JPEG, PNG, GIF, BMP, MP3, etc.
It supports multimedia hardware control to perform playback or recording using a camera
and microphone.
Android has an integrated open-source WebKit layout-based web browser to support
User Interfaces like HTML5, and CSS3.
Android supports multi-tasking means we can run multiple applications at a time and can
switch between them.
It will give a chance to reuse the application components and the replacement of native
applications.
It provides support for virtual reality or 2D/3D Graphics.
To
ma
r
●
●
Ro
mi
l
To
ma
r
Android Versions:
Google first publicly announced Android in November 2007 but was released on 23
SEPTEMBER 2008 to be exact. The first device to bring Android into the market was the HTC
Dream with the version Android 1.0. Since then, Google released a lot of android versions such
as Apple Pie, Banana Bread, Cupcake, Donut, Éclair, Froyo, Gingerbread, Jellybeans, Kitkat,
Lollipop, marshmallow, Nougat, Oreo, Pie, Android 10, Android 11, etc. with extra functionalities
and new features.
Programming Languages used in Developing Android Applications:
●
●
Java
Kotlin
Developing the Android Application using Kotlin is preferred by Google, as Kotlin is made an
official language for Android Development, which is developed and maintained by JetBrains.
Previously before Java is considered the official language for Android Development. Kotlin is
made official for Android Development in Google I/O 2017.
Advantages of Android Development:
To
ma
r
The Android is an open-source Operating system and hence possesses a vast community for
support.
The design of the Android Application has guidelines from Google, which becomes easier for
developers to produce more intuitive user applications.
Fragmentation gives more power to Android Applications. This means the application can run
two activities on a single screen.
Releasing the Android application in the Google play store is easier when it is compared to
other platforms.
Disadvantages of Android Development:
Ro
mi
l
Fragmentation provides a very intuitive approach to user experience but it has some drawbacks,
where the development team needs time to adjust to the various screen sizes of mobile
smartphones that are now available in the market and invoke the particular features in the
application.
The Android devices might vary broadly. So the testing of the application becomes more difficult.
As the development and testing consume more time, the cost of the application may increase,
depending on the application’s complexity and features.
Android Architecture
Android architecture contains different number of components to support any android device
needs. Android software contains an open-source Linux Kernel having collection of number of
C/C++ libraries which are exposed through an application framework services.
To
ma
r
Among all the components Linux Kernel provides main functionality of operating system
functions to smartphones and Dalvik Virtual Machine (DVM) provide platform for running an
android application.
The main components of android architecture are following:● Applications
● Application Framework
● Android Runtime
● Platform Libraries
● Linux Kernel
Ro
mi
l
Pictorial representation of android architecture with several main components and their sub
components –
Applications:
Applications is the top layer of android architecture. The pre-installed applications like home,
contacts, camera, gallery etc and third party applications downloaded from the play store like
chat applications, games etc. will be installed on this layer only.
It runs within the Android run time with the help of the classes and services provided by the
application framework.
To
ma
r
Application framework:
Application Framework provides several important classes which are used to create an Android
application. It provides a generic abstraction for hardware access and also helps in managing
the user interface with application resources. Generally, it provides the services with the help of
which we can create a particular class and make that class helpful for the Applications creation.
It includes different types of services activity manager, notification manager, view system,
package manager etc. which are helpful for the development of our application according to the
prerequisite.
Application runtime:
Android Runtime environment is one of the most important part of Android. It contains
components like core libraries and the Dalvik virtual machine(DVM). Mainly, it provides the base
for the application framework and powers our application with the help of the core libraries.
Ro
mi
l
Like Java Virtual Machine (JVM), Dalvik Virtual Machine (DVM) is a register-based virtual
machine and specially designed and optimized for android to ensure that a device can run
multiple instances efficiently. It depends on the layer Linux kernel for threading and low-level
memory management. The core libraries enable us to implement android applications using the
standard JAVA or Kotlin programming languages.
Platform libraries:
The Platform Libraries includes various C/C++ core libraries and Java based libraries such as
Media, Graphics, Surface Manager, OpenGL etc. to provide a support for android development.
●
●
●
●
●
●
Media library provides support to play and record an audio and video formats.
Surface manager responsible for managing access to the display subsystem.
SGL and OpenGL both cross-language, cross-platform application program interface
(API) are used for 2D and 3D computer graphics.
SQLite provides database support and FreeType provides font support.
Web-Kit This open source web browser engine provides all the functionality to display
web content and to simplify page loading.
SSL (Secure Sockets Layer) is security technology to establish an encrypted link
between a web server and a web browser.
Linux Kernel:
Linux Kernel is heart of the android architecture. It manages all the available drivers such as
display drivers, camera drivers, Bluetooth drivers, audio drivers, memory drivers, etc. which are
required during the runtime.
The features of Linux kernel are:
●
●
●
Security: The Linux kernel handles the security between the application and the system.
Memory Management: It efficiently handles the memory management thereby providing
the freedom to develop our apps.
Process Management: It manages the process well, allocates resources to processes
whenever they need them.
Network Stack: It effectively handles the network communication.
Driver Model: It ensures that the application works properly on the device and hardware
manufacturers responsible for building their drivers into the Linux build.
Ro
mi
l
●
●
To
ma
r
The Linux Kernel will provide an abstraction layer between the device hardware and the other
components of android architecture. It is responsible for management of memory, power,
devices etc.
DVM(Dalvik Virtual Machine)
Dalvik Virtual Machine is a Register-Based virtual machine. It was designed and written by Dan
Bornstein with contributions of other Google engineers as part of the Android mobile phone
platform. The Dalvik virtual machine was named after Bornstein after the fishing village “Dalvík”
in Eyjafjörður, Iceland, where some of his ancestors used to live.
Ro
mi
l
To
ma
r
Working of DVM:
The Java Compiler(javac) converts the Java Source Code into Java Byte-Code(.class). Then
DEX Compiler converts this (.class) file into in Dalvik Byte Code i.e. “.dex” file.
Application:
For Android, a new Virtual machine was developed by Google as stated above. It uses registers
of the CPU to store the operands. So no requirement of any pushing and popping of
instructions. Hence making execution faster. The instructions operate on virtual registers, being
those virtual registers memory positions in the host device. Register-based models are good at
optimizing and running on low memory. They can store common sub-expression results which
can be used again in the future. This is not possible in a Stack-based model at all. Dalvik Virtual
Machine uses its own byte-code and runs “.dex”(Dalvik Executable File) file.
Advantages:
● DVM supports the Android operating system only.
● In DVM executable is APK.
● Execution is faster.
● From Android 2.2 SDK Dalvik has it’s own JIT (Just In Time) compiler.
● DVM has been designed so that a device can run multiple instances of the Virtual
Machine effectively.
● Applications are given their own instances.
Ro
mi
l
To
ma
r
Disadvantages:
● DVM supports only Android Operating System.
● For DVM very few Re-Tools are available.
● Requires more instructions than register machines to implement the same high-level
code.
● App Installation takes more time due to dex.
● More internal storage is required.
Android SDK and it’s Components
Android SDK stands for Android Software Development Kit which is developed by Google
for Android Platform. With the help of Android SDK, we can create android Apps easily.
Ro
mi
l
To
ma
r
About Android SDK:
Android SDK is a collection of libraries and Software Development tools that are essential for
Developing Android Applications. Whenever Google releases a new version or update of
Android Software, a corresponding SDK also releases with it. In the updated or new version of
SDK, some more features are included which are not present in the previous version. Android
SDK consists of some tools which are very essential for the development of Android Application.
These tools provide a smooth flow of the development process from developing and debugging.
Android SDK is compatible with all operating systems such as Windows, Linux, macOS, etc.
Components of Android SDK:
Android SDK Components play a major role in the Development of Android applications. Below
are the important components:
1. Android SDK Tools:
Android SDK tool is an important component of Android SDK. It consists of a complete set of
development and debugging tools. Below are the SDK developer tools:
Ro
mi
l
To
ma
r
● Android SDK Build tool.
● Android Emulator.
● Android SDK Platform-tools.
● Android SDK Tools.
These are shown below :
2. Android SDK Build-Tools:
Android SDK build tools are used for building actual binaries of Android App. The main functions
of Android SDK Build tools are built, debug, run and test Android applications. The latest version
of the Android SDK Build tool is 30.0.3. While downloading or updating Android in our System,
one must ensure that its latest version is download in SDK Components.
3. Android Emulator:
An Android Emulator is a device that simulates an Android device on your system. Suppose we
want to run our android application that we code. One option is that we will run this on our
Android Mobile by Enabling USB Debugging on our mobile. Another option is using Android
Emulator. In Android Emulator the virtual android device is shown on our system on which we
run the Android application that we code.
Ro
mi
l
To
ma
r
Thus, it simply means that without needing any physical device Android SDK component
“Android Emulator” provides a virtual device on the System where we run our Application. The
emulator’s come with the configuration for Various android phones, tablets, Wear OS, and
Android TV devices.
In Android Virtual Emulator all functions that are feasible on real Android mobile is works on
virtual Device like:
●
●
●
●
phone calls, text messages.
stimulate different network speeds.
specify the location of a device
access on google play store and lot’s more.
But there is one disadvantage of this emulator is that. It is very slow when System’s PC has less
RAM. It works fine when a maximum GB of RAM is present on our device.
4. Android SDK Platform-tools:
Android SDK Platform-tools is helpful when we are working on Project and they will show the
error messages at the same time. It is specifically used for testing. It includes:
●
●
Android Debug Bridge (ADB), is a command-line tool that helps to communicate with the
device. It allows us to perform an action such as Installing App and Debugging App etc.
Fastboot allows you to flash a device with a new system image.
Systrace tools help to collect and inspect timing information. It is very crucial for App
Debugging.
To
ma
r
●
5. Android SDK Tools:
Android SDK tool is a component of SDK tool. It consists of a set of tools which and other
Utilities which are crucial for the development of Android Application. It contains the complete
set of Debugging and Development tools for android.
Ro
mi
l
6. SDK Platforms:
For Each Android Software, one SDK platform is available as shown below:
Like in this Android 11.0(R) is installed.
These are numbered according to the android version. The new version of the SDK platform
has more features and more compatible but the old version is less compatible with fewer
features. Like in Android 11.0(R) have more compatible and have more feature but the below
versions like Android 10.0(Q), Android4.4(KitKat) have less feature and is less compatible.
Ro
mi
l
To
ma
r
7. SDK Update Sites:
In SDK Update Sites, some sites are embedded in it which will check for Android SDK Updates
Tools. In this, one must ensure we don’t unclick the button below because these are checked by
default which will check for updates if we will unclick it then it doesn’t check updates for those.
Android Project folder Structure
Ro
mi
l
To
ma
r
Android Studio is the official IDE (Integrated Development Environment) developed by the
JetBrains community which is freely provided by Google for android app development. After
completing the setup of Android Architecture we can create an android application in the studio.
We need to create a new project for each sample application and we should understand the
folder structure. It looks like this:
The android project contains different types of app modules, source code files, and resource
files. We will explore all the folders and files in the android app.
To
ma
r
1. Manifests Folder
2. Java Folder
3. res (Resources) Folder
● Drawable Folder
● Layout Folder
● Mipmap Folder
● Values Folder
4. Gradle Scripts
Manifests Folder:
Manifests folder contains AndroidManifest.xml for creating our android application. This file
contains information about our application such as the Android version, metadata, states
package for Kotlin file, and other application components. It acts as an intermediator between
android OS and our application.
Ro
mi
l
Following is the manifests folder structure in the android application.
Java folder:
The Java folder contains all the java and Kotlin source code (.java) files that we create during
the app development, including other Test files. If we create any new project using Kotlin, by
default the class file MainActivity.kt file will create automatically under the package name
“com.example.myapplicationtest” as shown below.
To
ma
r
Ro
mi
l
Resource (res) folder:
The resource folder is the most important folder because it contains all the non-code sources
like images, XML layouts, and UI strings for our android application.
res/drawable folder:
It contains the different types of images used for the development of the application. We need to
add all the images in a drawable folder for the application development.
res/layout folder:
The layout folder contains all XML layout files which we used to define the user interface of our
application. It contains the activity_main.xml file.
To
ma
r
res/mipmap folder:
This folder contains launcher.xml files to define icons that are used to show on the home
screen. It contains different density types of icons depending upon the size of the device such
as hdpi, mdpi, xhdpi.
res/values folder:
Values folder contains a number of XML files like strings, dimensions, colors, and style
definitions. One of the most important files is the strings.xml file which contains the resources.
Ro
mi
l
Gradle Scripts folder:
Gradle means automated build system and it contains a number of files that are used to define
a build configuration that can be applied to all modules in our application. In build.gradle
(Project) there are buildscripts and in build.gradle (Module) plugins and implementations are
used to build configurations that can be applied to all our application modules.
Application Manifest File in Android
Every project in Android includes a Manifest XML file, which is AndroidManifest.xml, located in
the root directory of its project hierarchy. The manifest file is an important part of our app
because it defines the structure and metadata of our application, its components, and its
requirements. This file includes nodes for each of the Activities, Services, Content Providers,
and Broadcast Receiver that make the application, and using Intent Filters and Permissions
determines how they coordinate with each other and other applications.
To
ma
r
The manifest file also specifies the application metadata, which includes its icon, version
number, themes, etc., and additional top-level nodes can specify any required permissions, unit
tests, and define hardware, screen, or platform requirements. The manifest comprises a root
manifest tag with a package attribute set to the project’s package. It should also include an
xmls:android attribute that will supply several system attributes used within the file. We use the
versionCode attribute is used to define the current application version in the form of an integer
that increments itself with the iteration of the version due to update. Also, the versionName
attribute is used to specify a public version that will be displayed to the users.
We can also specify whether our app should install on an SD card of the internal memory using
the installLocation attribute. A typical manifest file looks as:
Ro
mi
l
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.myapplicationtest" >
<uses-sdk android:minSdkVersion="22"
android:targetSdkVersion="32"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplicationTest"
tools:targetApi="31" >
<activity
android:name=".SecondActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.MyApplicationTest" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
To
ma
r
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
2. uses-sdk:
It is used to define a minimum and maximum SDK version by means of an API Level integer
that must be available on a device so that our application functions properly, and the target SDK
for which it has been designed using a combination of minSdkVersion, maxSdkVersion, and
targetSdkVersion attributes, respectively. It is contained within the <manifest> element.
<uses-sdk android:minSdkVersion="22"
android:targetSdkVersion="32"/>
Ro
mi
l
3. uses-permission:
It outlines a system permission that must be granted by the user for the app to function properly
and is contained within the <manifest> element. When an application is installed (on Android 5.1
and lower devices or Android 6.0 and higher), the user must grant the application permissions.
<uses-permission android:name="android.permission.CAMERA"/>
4. application:
A manifest can contain only one application node. It uses attributes to specify the metadata for
your application (including its title, icon, and theme). During development, we should include a
debuggable attribute set to true to enable debugging, then be sure to disable it for your release
builds. The application node also acts as a container for the Activity, Service, Content Provider,
and Broadcast Receiver nodes that specify the application components. The name of our
custom application class can be specified using the android:name attribute.
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplicationTest"
tools:targetApi="31" >
</application>
To
ma
r
5. uses-library:
It defines a shared library against which the application must be linked. This element instructs
the system to add the library’s code to the package’s class loader. It is contained within the
<application> element.
<uses-library
android:name="android.test.runner"
android:required="true" />
Ro
mi
l
6. activity:
The Activity sub-element of an application refers to an activity that needs to be specified in the
AndroidManifest.xml file. It has various characteristics, like label, name, theme, launchMode,
and others. In the manifest file, all elements must be represented by <activity>. Any activity that
is not declared there won’t run and won’t be visible to the system. It is contained within the
<application> element.
<activity
android:name=".SecondActivity"
android:exported="false" />
7. intent-filter:
It is the sub-element of activity that specifies the type of intent to which the activity, service, or
broadcast receiver can send a response. It allows the component to receive intents of a certain
type while filtering out those that are not useful for the component. The intent filter must contain
at least one <action> element.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
8. action:
It adds an action for the intent-filter. It is contained within the <intent-filter> element.
<action android:name="android.intent.action.MAIN" />
9. category:
It adds a category name to an intent-filter. It is contained within the <intent-filter> element.
<category android:name="android.intent.category.LAUNCHER" />
To
ma
r
10. uses-configuration:
The uses-configuration components are used to specify the combination of input mechanisms
that are supported by our application. It is useful for games that require particular input controls.
It will be defined inside manifest tag.
<uses-configuration
android:reqTouchScreen="finger"
android:reqNavigation="trackball"
android:reqHardKeyboard="true"
android:reqKeyboardType="qwerty"/>
<uses-configuration
android:reqTouchScreen="finger"
android:reqNavigation="trackball"
android:reqHardKeyboard="true"
android:reqKeyboardType="twelvekey"/>
Ro
mi
l
11. uses-features:
It is used to specify which hardware features your application requires. This will prevent our
application from being installed on a device that does not include a required piece of hardware
such as NFC hardware, as follows:
<uses-feature android:name="android.hardware.nfc"/>
12. permission:
It is used to create permissions to restrict access to shared application components. We can
also use the existing platform permissions for this purpose or define your own permissions in
the manifest.
<permission
android:name="com.paad.DETONATE_DEVICE"
android:protectionLevel="dangerous"
android:label="Self Destruct"
android:description="@string/detonate_description">
</permission>
Ro
mi
l
To
ma
r
Related documents
Download