0% found this document useful (0 votes)
138 views

MAD _Unit_1_Notes Introduction to Android

The document provides an introduction to Android platform and architecture, detailing its significance in mobile application development and the core components such as activities, services, and intents. It discusses the Android operating system's market share, features, and architecture, including the Linux kernel and application framework. Additionally, it covers the activity lifecycle and the differences between Dalvik and Android Runtime (ART).

Uploaded by

kashbet605
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)
138 views

MAD _Unit_1_Notes Introduction to Android

The document provides an introduction to Android platform and architecture, detailing its significance in mobile application development and the core components such as activities, services, and intents. It discusses the Android operating system's market share, features, and architecture, including the Linux kernel and application framework. Additionally, it covers the activity lifecycle and the differences between Dalvik and Android Runtime (ART).

Uploaded by

kashbet605
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
You are on page 1/ 21

Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

B.C.A. Third Year V Semester

Mobile Application Development (Subject Code BCA-503)

UNIT I: Introduction to Android

1.1 Introduction to Android platform and Architecture

1.2 Basic components of Android, activity life cycle

1.3 Features of ART & Dalvik Virtual machine

1.4 Android Application Structure, device screen size compatibility

1.5 Android emulator, working with AndroidManifest.xml.

1.1 INTRODUCTION TO ANDROID PLATFORM AND ARCHITECTURE


Introduction to Mobile Programming

Mobile Programming is the process of making software for smartphones and digital
assistants, most commonly for Android and iOS.

The software can be preinstalled on the device, downloaded from a mobile app store or
accessed through a mobile web browser.

The programming and markup languages used for this kind of software development include
Java, Kotlin, Swift, C# and HTML5, CSS, XML and JavaScript etc.

Before going into details let us discuss why mobile programming and development is
important now a day.

According to recent data and survey an average smartphone user spent 3 hours and 15
minutes on a smartphone every day. This is longer than the time spent watching TV, or
engaging with any other media.

About 90% of this time was spent in apps. Clearly, mobile apps are the biggest medium your
customers are engaging with digitally.

Smartphone users have an average of 80 apps installed on their phone and use at least 40 of
them every month.

A mobile app is the best way to either build a business from scratch, or increase your existing
business and give it a digital edge

The evolution of mobile application development technology with new devices made our
lives much easier.

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 1


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

Introduction to Android

Android is an OS for mobile devices such as smart phones, tablet computers etc.

It is developed by Open Handset Alliance led by Google.

Google released most of the Android code under the Apache License, a free software license.

Android, Inc. was founded in Palo Alto, California, United States in October, 2003 by Andy
Rubin, Rich Miner, Nick Sears and Chris White.

Google acquired Android Inc. on August 17, 2005, making Android Inc. a wholly owned
subsidiary of Google Inc.

Following Tables shows the Android and other operating system Market Shares.

Operating System Market Shares(2023)

Android 70.89

iOS 28.36

Samsung 0.38

Kai OS 0.18

Other 0.02

With 70.89 Market Share in 2023 Android is becoming the dominating operating system in
smart phone world.

Android Features

Following are some of the important features of android OS

 Android OS is a Linux based operating system.


 Android SDK provides the tools and APIs necessary for application development using
JAVA.
 Android’s libraries cover telephony, video, graphics, UI programming, and a number of
other aspects of the device.
 Android offers its own optimized JVM to run the compiled Java class files.
 Application framework enabling reuse and replacement of components.
 Dalvik virtual machine optimized for mobile devices.
 Integrated browser based on the open source WebKit engine.
 2D 3D graphics support
 SQLite Database

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 2


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

 Media support for common audio, video, and still image formats (MPEG4, H.264, MP3,
AAC, AMR, JPG, PNG, GIF)
 GSM(Global System for Mobile Communication) Telephony (hardware dependent)
 Bluetooth, EDGE(Enhance Data Rate for GSM Evolution), 3G, and WiFi (hardware
dependent)
 Camera, GPS, compass, and accelerometer (hardware dependent)
 Rich development environment including a device emulator, tools for debugging.
ANDROID ARCHITECTURE

The Android Architecture generally consists of a Linux kernel and a collection of C/C++
libraries that is an application framework that provides services, and management of the
applications and run time.

Linux Kernel
Android was created on the open source kernel of Linux. One main reason for choosing
this kernel was that it provided core features on which to develop the Android
operating system. The features of Linux kernel are:
1. Security:
The Linux kernel handles the security between the application and the system.
2. Memory Management:
It efficiently handles the memory management
3. Process Management:
It manages the process well, allocates resources to processes whenever they need
them.
4. Network Stack:
It effectively handles the network communication.
5. Driver Model:
It ensures that the application works. Hardware manufacturers can build their drivers
into the Linux build.

Libraries:
Running on the top of the kernel, the Android framework was developed with various
features. It consists of various C/C++ core libraries with numerous of open source tools. Some
of these are:

The Android runtime:


The Android runtime consist of core libraries of Java and ART(the Android RunTime).
Older versions of Android (4.x and earlier) had Dalvik runtime.
Open GL (graphics library):
This cross-language, cross-platform application program interface (API) is used to
produce 2D and 3D computer graphics.
WebKit:
This open source web browser engine provides all the functionality to display web
content and to simplify page loading.
Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 3
Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

Media frameworks:
These libraries allow you to play and record audio and video.
Secure Socket Layer (SSL):
These libraries are there for Internet security.

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.

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
Pictorial representation of android architecture with several main
components and their sub components –

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 4


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

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.
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 Free Type 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.

1.2 BASIC COMPONENTS OF ANDROID, ACTIVITY LIFE CYCLE

An android component is simply a piece of code that has a well-defined life cycle e.g. Activity,
Receiver, Service etc.

The core building blocks or fundamental components of android are activities, views,
intents, services, content providers, fragments and AndroidManifest.xml.

1. Activity

An activity is a class that represents a single screen. It is like a Frame in AWT.


Activities are said to be the presentation layer of our applications. The UI of our application
is built around one or more extensions of the Activity class. By using Fragments and Views,

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 5


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

activities set the layout and display the output and also respond to the user’s actions. An
activity is implemented as a subclass of class Activity.
public class MainActivity extends Activity {
}

2. Services

Services are like invisible workers of our app.


These components run at the backend, updating your data sources and Activities, triggering
Notification, and also broadcast Intents.
They also perform some tasks when applications are not active. A service can be used as a
subclass of class Service:
public class ServiceName extends Service {
}

3. View/Widgets

A view is the UI element such as button, label, text field etc. Anything that you see is a view.
4. Intents

Intent is used to invoke components. It is mainly used to:

 Start the service


 Launch an activity
 Display a web page
 Display a list of contacts
 Broadcast a message
 Dial a phone call etc.
5. Content Providers:

Content Providers are used to share data between the applications.

6. Fragments

Fragments are like parts of activity. An activity can display one or more fragments on the
screen at the same time.
7. Broadcast Receivers

 They are known to be intent listeners


 It listen to the Intents that satisfy the matching criteria specified by us.
 Broadcast Receivers make our application react to any received Intent thereby making
them perfect for creating event-driven applications.

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 6


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

8. Notifications

Notifications are the application alerts that are used to draw the user’s attention to some
particular app event without stealing focus or interrupting the current activity of the user.
They are generally used to grab user’s attention when the application is not visible or
active,
Examples: E-mail popups, Messenger popups, etc.
ACTIVITY LIFE CYCLE:

An activity represents a single screen with a user interface just like window or frame.
Activity is the subclass of AppCompactActivity class.
If you have worked with C, C++ or Java programming language then you must have seen
that your program starts from main() function.
Very similarway, Android system initiates its programwith
in an Activity starting with a call on onCreate() method.
Activity class is one of the very important parts of the
Android component.
Any app, don’t matter how much small it is (in terms of code and scalability), it has at least
one Activity class.
So it can be said that an activity is the entry point for interacting with the user.
Every activity contains the layout, which has a user interface to interact with the user.
As we know that every activity contains a layout associated with it, so it can be said that
activity class is the gateway, through which a user can interact programmatically with UI.
Layout for a particular activity is set with the help of setContentView().
setContentView() is a function that takes View as a parameter.
As a user navigates through, out of, and back to your app, the Activity
instances in your app transition through different states in their lifecycle.
The Activity class provides a number of functions that allow the activity to know that a
state has changed: that the system is creating, stopping, or resuming an activity, or
destroying the process in which the activity resides.

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 7


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

Activity Life Cycle is Represented in Following Diagram.

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 8


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

Android Activity Lifecycle is controlled by 7 methods

Method Description

onCreate called when activity is first created.

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
}
onStart called when activity is becoming visible to the user.

@Override

protected void onStart() {

super.onStart();

onResume called when activity will start interacting with the user.

@Override

protected void onResume() {

super.onResume();

onPause called when activity is not visible to the user.

@Override

protected void onPause() {

super.onPause();

onStop called when activity is no longer visible to the user.

@Override

protected void onStop() {

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 9


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

super.onStop();

onRestart called after your activity is stopped, prior to start.

@Override

protected void onRestart() {

super. onRestart ();

onDestroy called before the activity is destroyed.

@Override

protected void onDestroy() {

super. onDestroy ();

1.3 FEATURES OF ART & DALVIK VIRTUAL MACHINE

DALVIK VIRTUAL MACHINE

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 name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.

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.

Let's see the compiling and packaging process from the source file:

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 10


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

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.

DVM features:

 Register-based architecture. The data structure with methods placed there is based on
processor registers. Instructions in register VM are executed faster than similar ones in stack VM
 Executes the bytecode of its format. Android dexer converts .class files into .dex format
optimized for DVM execution. Unlike a .class file, a .dex file contains several classes at once.

ANDROID RUNTIME (ART)


Android runtime (ART) is the managed runtime used by applications and some system services on
Android.
ART and its predecessor Dalvik were originally created specifically for the Android project.
ART as the runtime executes the Dalvik Executable format and Dex bytecode specification.
ART and Dalvik are compatible runtimes running Dex bytecode, so apps developed for Dalvik
should work when running with ART. However, some techniques that work on Dalvik do not work
on ART

ART Features.
 Ahead-of-time (AOT) compilation
 ART introduces ahead-of-time (AOT) compilation, which can improve app performance.
ART also has tighter install-time verification than Dalvik.
 Improved garbage collection
 Garbage collection (GC) is very resource intensive, which can impair an app's
performance, resulting in choppy display, poor UI responsiveness, and other problems.
ART improves garbage collection in several ways
 Development and debugging improvements
 ART offers a number of features to improve app development and debugging.
Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 11
Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

ART supports a number of new debugging options, particularly in monitor- and garbage
collection-related functionality
1.4 ANDROID APPLICATION STRUCTURE, DEVICE SCREEN SIZE COMPATIBILITY
ANDROID APPLICATION STRUCTURE

Android Application structure is made up of several important files and folder that are
required for creating android applications.

Some important files/folders, and their significance need to understands


for easy understanding of the Android studio work environment.
In the below image, several important files are marked:

All of the files marked in the above image are explained below in brief:

1. AndroidManifest.xml: Every project in Android includes a manifest file, which is


AndroidManifest.xml, stored in the root directory of its project hierarchy. The manifest file
Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 12
Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

is an important part of our app because it defines the structure and metadata of our
application, itscomponents, 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 co-ordinate with each other and other applications.
A typical AndroidManifest.xml file looks like:

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.geeksforgeeks.geeksforgeeks">
<application android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

2. Java: The Java folder contains the Java source code files. These files are used as a
controller for controlled UI (Layout file). It gets the data from the Layout file and after
processing that data output will be shown inthe UI layout. It works on the backend of an
Android application.
3. drawable: A Drawable folder contains resource type file (something that can be
drawn). Drawables may take a variety of file like Bitmap (PNG, JPEG), Nine Patch, Vector
(XML), Shape, Layers, States, Levels, and Scale.
4. layout: A layout defines the visual structure for a user interface, suchas the UI for
an Android application. This folder stores Layout files that are written in XML language.
You can add additional layout objects or widgets as child elements to gradually build a View
hierarchy that defines your layout file.
Below is a sample layout file:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 13


Notes: Mobile Application Development Class: BCA TY, Unit I: Introduction to Android

android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
</LinearLayout>
5. mipmap: Mipmap folder contains the Image Asset file that can be used
in Android Studio application. You can generate the following icon types like Launcher
icons, Action bar and tab icons, and Notification icons.
6. colors.xml: colors.xml file contains color resources of the Android application.
Different color values are identified by a unique name that can be used in the Android
application program.
Below is a sample colors.xml file:

<?xml version="1.0" encoding="utf-8"?>


<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
7. strings.xml: The strings.xml file contains string resources of the
Android application. The different string value is identified by a unique name that can be
used in the Android application program. This file also stores string array by using XML
language.
Below is a sample colors.xml file:

<resources>
<string name="app_name">MyApp</string>
</resources>
8. styles.xml: The styles.xml file contains resources of the theme style in
the Android application. This file is written in XML language.Below is a sample
styles.xml file:

<resources>

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur. 14


Notes: Mobile Application Development, Class: BCATY, Unit I: Introduction to Android

<!-- Base application theme. -->


<style name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
9. build.gradle(Module: app): This defines the module-specific build
Configurations. Here you can add dependencies what you need in your
Android application.

apply plugin:
'com.android.application'android {
compileSdkVersion
26defaultConfig {
applicationId "com.example.geeksforgeeks.geeksforgeeks"minSdkVersion
16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTy
pes {
release
{
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation
'com.android.support:appcompat-v7:26.1.0'
implementation
'com.android.support.constraint:cons
traint-layout:1.0.2'
}

DEVICE SCREEN SIZE COMPATIBILITY

Android devices come in a variety of screen sizes and resolutions. That’s why
handling the multiple screen size in android is most important.

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur Page 15
Notes: Mobile Application Development, Class: BCATY, Unit I: Introduction to Android

Actual physical size, measured as the screen’s diagonal. For simplicity, Android
groups has four generalized sizes: small, normal, large, and extra large. To set up
support for multiple device sizes in Android, add the element into the
AndroidManifest.xml file.

<?xml version="1.0" encoding="utf-8"?>


<manifest>

<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens= "true"
android:anyDensity="true"
/>

<application... >

Support for different screen sizes enables the greatest number of users and widest
variety of devices to access your app.

To support as many screen sizes as possible, design your app layouts to be responsive
and adaptive

Window size classes in android categorize the display area available to your app
as compact, medium, or expanded. Available width and height are classified separately

To ensure that your layout is responsive to different screen sizes,


use wrap_content, match_parent, or 0dp (match constraint) for the width and height of
most view components instead of hard-coded values:

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur Page 16
Notes: Mobile Application Development, Class: BCATY, Unit I: Introduction to Android

 wrap_content — Enables the view to set its size to whatever is necessary to fit the
content contained in the view.
 match_parent — Enables the view to expand as much as possible within the parent
view.
 0dp (match constraint) — In a ConstraintLayout, similar to match_parent. Enables
the view to take all the available space within the view's constraints.

1.5 ANDROID EMULATOR, WORKING WITH ANDROIDMANIFEST.XML

ANDROID EMULATOR

The Android emulator is an Android Virtual Device (AVD), which represents a specific
Android device. We can use the Android emulator as a target device to execute and test our
Android application on our PC.

The Android emulator provides almost all the functionality of a real device. We can get the
incoming phone calls and text messages. It also gives the location of the device and
simulates different network speeds.

Android emulator simulates rotation and other hardware sensors. It accesses the Google
Play store, and much more

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur Page 17
Notes: Mobile Application Development, Class: BCATY, Unit I: Introduction to Android

Testing Android applications on emulator are sometimes faster and easier than doing on a
real device. For example, we can transfer data faster to the emulator than to a real device
connected through USB.

The Android emulator comes with predefined configurations for several Android phones,
Wear OS, tablet, Android TV devices.

The emulator offers these advantages:

 Flexibility: In addition to being able to simulate a variety of devices and Android


API levels, the emulator comes with predefined configurations for various Android
phone, tablet, Wear OS, and Android TV devices.
 High fidelity: The emulator provides almost all the capabilities of a real Android
device. You can simulate incoming phone calls and text messages, specify the
location of the device, simulate different network speeds, simulate rotation and
other hardware sensors, access the Google Play Store, and much more.
 Speed: Testing your app on the emulator is in some ways faster and easier than
doing so on a physical device. For example, you can transfer data faster to the
emulator than to a device connected over USB.

The Android emulator takes additional requirements beyond the basic system
requirement for Android Studio. These requirements are given below:

o SDK Tools 26.1.1 or higher


o 64-bit processor
o Windows: CPU with UG (unrestricted guest) support
o HAXM(Hardware Accelerated Execution Manager) 6.2.1 or later (recommended
HAXM 7.2.0 or later)

The Android emulator is installed while installing the Android Studio. However some
components of emulator may or may not be installed while installing Android Studio. To
install the emulator component, select the Android Emulator component in the SDK
Tools tab of the SDK Manager.

We can run an Android app form the Android Studio project, or we can run an app which
is installed on the Android Emulator as we run any app on a device.

To start the Android Emulator and run an application in our project:

1. In Android Studio, we need to create an Android Virtual Device (AVD) that the emulator
can use to install and run your app. To create a new AVD:-

2. Open the AVD Manager by clicking Tools > AVD Manager.

3. Select the system image for the particular API level and click Next.

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur Page 18
Notes: Mobile Application Development, Class: BCATY, Unit I: Introduction to Android

4. Change AVD properties if needed, and then click Finish.

5. In the toolbar, choose the AVD, which we want to run our app from the target device
from the drop-down menu.

WORKING WITH ANDROIDMANIFEST.XML

Every project in Android includes a manifest file, which is


AndroidManifest.xml, stored 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 co-ordinate with each other and other
applications.
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 of 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 version Code attribute is used to define the current application version
in the form of an integer that increments itself with the iteration of version due
to updation.
Also, version Name 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 install Location attribute.
We can also specify whether our app should install on an SD card of the internal
memory using the install Location attribute.
A typical manifest node looks as:

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.paad.myapp"
android:versionCode="1"
android:versionName="0.9 Beta"
android:installLocation="preferExtern
al">[....manifest nodes ]
</manifest>

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur Page 19
Notes: Mobile Application Development, Class: BCATY, Unit I: Introduction to Android

A manifest file includes the nodes that define the application components,
security settings, test classes and requirements that make up the application.
Some of the manifest sub-node tags that are mainly used are:
uses-sdk– It is used to define a minimum and maximum SDK version that must
be available on a device so that our application function properly, and target SDK
for which it has been designed using a combination of minSdkVersion,
maxSdkVersion, and targetSdkVersion attributes, respectively.

<uses-sdk android:minSdkVersion=”6”

android:targetSdkVersion=”15”/>

uses-configuration– The uses-configuration nodes 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.

<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”/>

uses-features– It is used to specify which hardware features your application


requirement. This will prevent our application from being
installed on a device that does not include a required piece of hardwaresuch as
NFC hardware, as follows:

<uses-feature android:name=”android.hardware.nfc”/>

supports-screens– It is used to describe the screen support for our


application:

<supports-screens android:smallScreens=”false”
android:normalScreens=”true”
android:largeScreens=”true”
android:xlargeScreens=”true”/>

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.

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur Page 20
Notes: Mobile Application Development, Class: BCATY, Unit I: Introduction to Android

<uses-permission
android:name="android.permission.INTERNET"></uses-
permission>

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 theapplication components.
The name of our custom application class can be specified using the
android:name attribute.

<application android:icon="@drawable/icon"
android:logo-"@drawable/logo" android:theme="@android:style/Theme.Light"
android:name=".MyApplicationClass" android:debuggable="true">
[....application nodes. ............................................. ]

</application>

Prepared By: Mr. D. R. Somwanshi (M.Sc.CS, M.Phil, CS) COCSIT Latur Page 21

You might also like