0% found this document useful (0 votes)
7 views77 pages

Unit1 (Mad)

Uploaded by

21r21a0599
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)
7 views77 pages

Unit1 (Mad)

Uploaded by

21r21a0599
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/ 77

UNIT-I:

Introduction to Android: The Android Platform,


Prerequisites of Android, Android SDK, Android
studio Installation, Building you First Android
application, Understanding Anatomy of Android
Application, Android Manifest file.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 1
Android
4.0 International License
Introduction to Android

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
What is Android?
● Mobile operating system based on Linux kernel
● User Interface for touch screens
● Used on over 80% of all smartphones
● Powers devices such as watches, TVs, and cars
● Over 2 Million Android apps in Google Play store
● Highly customizable for devices / by vendors
● Open source

This work is licensed under a Creative


Android DeveloperIntroduction
Android Developer Fundamentals
Android
to
Fundamentals Commons Attribution-NonCommercial 3
4.0 International License
Android user interaction
● Touch gestures: swiping, tapping, pinching
● Virtual keyboard for characters, numbers, and emoji
● Support for Bluetooth, USB controllers and peripherals

This work is licensed under a Creative


Android DeveloperIntroduction
Android Developer Fundamentals
Android
to
Fundamentals Commons Attribution-NonCommercial 4
4.0 International License
History of Android
●Google acquired the startup company Android Inc. in 2005 to start the development of
the Android Platform. The key players at Android Inc. included Andy Rubin, Rich Miner,
Nick Sears, and Chris White.
●In late 2007, a group of industry leaders came together around the Android Platform to
form the Open Handset Alliance (http://www.openhandsetalliance.com).
●The Android SDK was first issued as an “early look” release in November 2007.
●In September 2008 T-Mobile announced the availability of the T-Mobile G1, the first
smartphone based on the Android Platform.
●A few days after that, Google announced the availability of Android SDK Release
Candidate 1.0.
●In October 2008, Google made the source code of the Android Platform available under
Apache’s open source license.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
History of Android

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
What is Open Handset Alliance?
●Quoting from www.OpenHandsetAlliance.com page
●“… Open Handset Alliance™, a group of 47 technology and mobile
companies have come together to accelerate innovation in mobile and offer
consumers a richer, less expensive, and better mobile experience.
●Together we have developed Android™, the first complete, open, and free
mobile platform.
●We are committed to commercially deploy handsets and services using the
Android Platform. “
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
What is the Open Handset Alliance (OHA)?

→ It's a consortium of several companies

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Google Android
Android
4.0 International License
Phones

HTC G1,
Droid, Motorola Droid (X)
Tattoo

Suno S880 Samsung Galaxy Sony Ericsson


Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 9
4.0 International License
The Android
Platform/Architecture/
Android Stack

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Android stack:
1. System and user apps
2. Android OS API in Java
framework
3. Expose native APIs;
run apps
4. Expose device hardware
capabilities
5. Linux Kernel

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Platform - The Android Software Stack

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
1. System and user apps

● Android provides a set of core applications:


✓ Email Client
✓ SMS Program
✓ Calendar
✓ Maps
✓ Browser
✓ Contacts
✓ Etc
● All applications are written using the Java language.
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 13
4.0 International License
2. JAVA API

Most of the application framework accesses these core


libraries through the Dalvik VM, the gateway to the
Android Platform

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 14
4.0 International License
2. JAVA API
Feature Role

View Used to build an application, including lists, grids, text


System boxes, buttons, and embedded web browser

Content Enabling applications to access data from other


Provider applications or to share their own data

Resource Providing access to non-code resources (localized string


Manager , graphics, and layout files)

Notification Enabling all applications to display customer alerts in the


Manager status bar

Activity Managing the lifecycle of applications and providing


Manager a common navigation backstack

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 15
4.0 International License
3. C/C++ Libraries and Andriod Runtime

● Including a set of C/C++ libraries used by components of the Android system


as support libraries to JAVA API
● Exposed to developers through the Android application framework

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 16
4.0 International License
3. C/C++ Libraries and Andriod Runtime
●The media libraries are based on PacketVideo’s (http://www.packetvideo.com/)
OpenCORE. These libraries are responsible for recording and playback of audio and
video formats.
●A library called Surface Manager controls access to the display system and
supports 2D and 3D.
●The WebKit library is responsible for browser support; it is the same library that
supports Google Chrome and Apple Inc.’s Safari.
●The FreeType library is responsible for font support.
●SQLite (http://www.sqlite.org/) is a relational database that is available on the
device itself.
●SQLite is also an independent open source effort for relational databases and not
directly tied to Android. You can acquire and use tools meant for SQLite for Android
databases as well.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
3. C/C++ Libraries and Andriod Runtime
●Dalvik Virtual Machine (Cont)
✓Executing the Dalvik Executable (.dex) format
➢.dex format is optimized for minimal memory footprint.

➢Compilation

✓Relying on the Linux Kernel for:


➢Threading

➢Low-level memory management

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 18
4.0 International License
Android applications are compiled to Dalvik bytecode

Write app in Java

Compiled in Java

Transformed to Dalvik bytecode

Loaded into Dalvik VM

Linux OS

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
4. C/C++ Libraries and Andriod Runtime:

The HAL consists of multiple library modules, each of which implements an


interface for a specific type of hardware component, such as
the camera or bluetooth module.
 When a framework API makes a call to access device hardware, the
Android system loads the library module for that hardware component.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
5. Linux Kernel

● Relying on Linux Kernel 2.6 for core system services

✓ Memory and Process Management

✓ Network Stack

✓ Drivers

✓ Security

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 21
4.0 International License
Prerequisites of Android

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
•Software Requirements: JDK
•Hardware Requirements:
• Microsoft Windows 7/8/10 ( 64-bit) or Linux
•4 GB RAM minimum, 8 GB RAM recommended (plus 1 GB for the Android
Emulator)
•2 GB of available disk space minimum, 4 GB recommended

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Android SDK

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Android SDK:A software development kit that enables developers to create
applications for the Android platform. The Android SDK includes sample
projects with source code, development tools, an emulator, and required
libraries to build Android applications. The different SDK tools are:
 Editors
 Debugger
 Emulator
 Libraries
 Monitors
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
● Android Editors: Android editors are text or source code editor
which is used to write the code and following are the advantages
of Android editor
 Provides Syntax highlighting for xml and java code

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
XML editor Java Editor

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
● Debugger: Android Studio provides a debugger that allows you to do the
following and more:
 Select a device to debug your app on.
 Set breakpoints in your Java, Kotlin, and C/C++ code.
 Examine variables and evaluate expressions at runtime.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Breakpoints in java Code Debugging process

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
● Emulator: An Android emulator is an Android Virtual Device (AVD)
that represents a specific Android device.
● You can use an Android emulator as a target platform to run and test
your Android applications on your PC.
● Using Android emulators is optional

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Creating Emulator

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
● Libraries: We can add the external libraries using dependencies in android
● We can get the external libraries from android developer site or other sites.
● For every component the
dependency is available in
developer site. Copy the dependency
and paste in build.gradle(app) in
your application. After adding the
Dependency we can use the
Corresponding component in the
Application.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
● Monitors: Monitor is a tool used to monitor your android application.
● Device file explorer is one of the monitor
which is useful when examining files
that are created by your app or if you
want to transfer files to and from a
device.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Android studio Installation

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Step – 1 :
Download get the Android Studio executable or zip file from Android Studio.
Step – 2 :
Click on the download android studio button .

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Click on the “I have read and agree with the above terms and conditions” checkbox
followed by the download button.

Click on Save file button in the appeared prompt box and the file will start
downloading .

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Step – 3:
After the downloading has finished, open the file from downloads and run it .
It will prompt the following dialogue box .

Click on next .
In the next prompt it’ll ask for a path for installation. Choose a path and hit next.
Note :The installation path should have the required minimum space.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Step – 4 :
It will start the installation, and once it is completed, it will be like the image shown below .

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Step – 5
Once “Finish” is clicked, it will ask whether the previous settings needs to be impoerted [if android
studio had been installed earlier], or not.
It is better to choose the ‘Don’t import Settings option’ .

Click the OK button.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Step – 6 :
This will start the Android Studio.

Meanwhile it will be finding the available SDK components

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Step – 7:
After it has found the SDK components, it will redirect to the Welcome dialog box .

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Choose Standard and click on Next.
Now choose the theme, whether Light theme or the Dark one .
The light one is called the IntelliJ theme whereas the dark theme is called Darcula .
Choose as required.

Click on the Next button

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Step – 8 :
Now it is time to download the SDK components .

Click on Finish .

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
It has started downloading the components

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
The Android Studio has been successfully configured.
Now it’s time to launch and build apps.
Click on the Finish button to launch it.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Step – 9 :
Click on ‘Start new android project’ to build a new app.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
4.0 International License
Building you First Android
application

This work is licensed under a Creative


Android DeveloperIntroduction
Android Developer Fundamentals
Android
to
Fundamentals Commons Attribution-NonCommercial 48
4.0 International License
First Android Application:
To create your new Android project, follow these steps:
1. In the Welcome to Android Studio window, click Start a new Android Studio
project.
If you have a project already opened, select File > New > New Project.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 49
Android
4.0 International License
First Android Application:
2. Inthe Choose your project window, select Empty View
Activity and click Next.
3. In the Configure your project window, complete the following:
Enter "My First App" in the Name field.
Enter "com.example.myfirstapp" in the Package name field.
If you'd like to place the project in a different folder, change
its Save location.
Select either Java or Kotlin from the Language drop-down
menu.
Select the checkbox next to Use androidx.* artifacts.
Leave the other options as they are.
4. Click Finish.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 50
4.0 International License
First Android Application:
After some processing time, the Android Studio main window appears.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial
Android
@2010 Mihail L. Sichitiu 51
4.0 International License
First Android Application:
Now take a moment to review the most important files.

First, be sure the Project window is open (select View > Tool Windows >
Project) and the Android view is selected from the drop-down list at the
top of that window.
You can then see the following files:
app > java > com.example.myfirstapp > MainActivityThis is the main
activity. It's the entry point for your app. When you build and run your app,
the system launches an instance of this Activity and loads its layout.

app > res > layout > activity_main.xmlThis XML file defines the layout for
the activity's user interface (UI). It contains a TextView element with the
text "Hello, World!"
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial 52
Android
4.0 International License
First Android Application:
app > manifests > AndroidManifest.xmlThe manifest file describes the
fundamental characteristics of the app and defines each of its
components.

Gradle Scripts > build.gradleThere are two files with this name: one for
the project, "Project: My First App," and one for the app module, "Module:
app." Each module has its own build.gradle file, but this project currently
has just one module. Use each module's build.file to control how
the Gradle plugin builds your app. For more information about this file,
see Configure your build.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 53
Android
4.0 International License
Understanding Anatomy of
Android Application

This work is licensed under a Creative


Android DeveloperIntroduction
Android Developer Fundamentals
Android
to
Fundamentals Commons Attribution-NonCommercial 54
4.0 International License
Anatomy of Android Application

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 55
Android
4.0 International License
Anatomy of Android Application
Manifests Folder

This folder will contain a manifest file (AndroidManifest.xml) for our android
application.

This manifest file will contain information about our application such as android
version, access permissions, metadata, etc. of our application and its components.

The manifest file will act as an intermediate between android OS and our
application.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 56
Android
4.0 International License
Anatomy of Android Application
Following is the structure of mainfests folder in android application.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 57
Android
4.0 International License
Anatomy of Android Application
Java Folder:
This folder will contain all the java source code (.java) files which we’ll create
during the application development.
Whenever we create any new project / application, by default the class
file MainActivity.java will create automatically under the package name
“com.example.helloworld” like as shown below.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 58
Android
4.0 International License
Anatomy of Android Application
res (Resources) Folder:
It’s an important folder which will contain all non-code resources, such as bitmap
images, UI strings, XML layouts like as show below.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 59
Android
4.0 International License
Anatomy of Android Application
The res (Resources) will contain a different
type of folders those are

Drawable Folder (res/drawable):


It will contains the different type of images as
per the requirement of application. It’s a best
practice to add all the images
in drawable folder other than app / launcher
icons for the application development.

Layout Folder (res/layout):


This folder will contain all XML layout files
which we used to define the user Interface of
our application.
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial 60
Android
4.0 International License
Anatomy of Android Application
Mipmap Folder (res/mipmap):

This folder will contain app / launcher


icons which are used to show on the home
screen. It will contain different density type
of icons such as hdpi, mdpi, xhdpi, xxhdpi,
xxxhdpi, to use different icons based on
the size of device.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 61
Android
4.0 International License
Anatomy of Android Application
Values Folder (res/values):

This folder will contain a various


XML files, such as strings, colors,
styles definitions and static array of
strings or integers. Following is the
structure of values folder in android
application.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 62
Android
4.0 International License
Android Manifest file.

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 63
Android 4.0 International License
Android Manifest file
Every app project must have an AndroidManifest.xml file (with precisely that name) at the root
of the project source set. The manifest file describes essential information about your app.
Among many other things, the manifest file is required to declare the following:
The app's package name, which usually matches your code's namespace. When packaging
the app, the build tools replace this value with the application ID from the Gradle build files,
which is used as the unique app identifier on the system and on Google Play
The components of the app, which include all activities, services, broadcast receivers, and
content providers(Building blocks of android).
The permissions that the app needs in order to access protected parts of the system or other
apps. It also declares any permissions that other apps must have if they want to access content
from this app.
The hardware and software features the app requires, which affects which devices can install
the app from Google Play.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 64
Android
4.0 International License
Android Manifest file
File features: The following sections describe how some of the most important
characteristics of your app are reflected in the manifest file.
i. Package name and application ID:
The manifest file's root element requires an attribute for your app's package name

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
...
</manifest>

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 65
Android
4.0 International License
Android Manifest file
While building your app into the final application package (APK), the Android
build tools use the package attribute for two things:
It applies this name as the namespace for your app's
generated R.java class (used to access your app resources).Example: With
the above manifest, the R class is created at com.example.myapp.R.
It uses this name to resolve any relative class names that are declared in
the manifest file.Example: With the above manifest, an activity declared as
<activity android:name=".MainActivity"> is resolved to
be com.example.myapp.MainActivity.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 66
Android
4.0 International License
Android Manifest file
ii. App components:
For each app component that you create in your app, you must declare a corresponding
XML element in the manifest file:
<activity> for each subclass of Activity.
<service> for each subclass of Service.
<receiver> for each subclass of BroadcastReceiver.
<provider> for each subclass of ContentProvider.

<manifest ... >


<application ... >
<activity android:name="com.example.myapp.MainActivity" ... >
</activity>
</application>
</manifest>

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 67
Android
4.0 International License
Android Manifest file
iii. Intent filters:

When an app issues an intent to the system, the system locates


an app component that can handle the intent based on intent
filter declarations in each app's manifest file. The system
launches an instance of the matching component and passes
the Intent object to that component.

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 68
Android
4.0 International License
Android Manifest file
iv. Icons and labels:
A number of manifest elements have icon and label attributes for displaying a small icon
and a text label, respectively, to users for the corresponding app component.

v. Permissions:
Android apps must request permission to access sensitive user data (such as contacts
and SMS) or certain system features (such as the camera and internet access). Each
permission is identified by a unique label.

<manifest ... >


<uses-permission android:name="android.permission.SEND_SMS"/>
...
</manifest>
Your app can also define its own permissions. A new permission is declared with
the <permission> element.
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial 69
Android
4.0 International License
Android Manifest file
vi. Device compatibility:
The manifest file is also where you can declare what types of hardware or software features
your app requires, and thus, which types of devices your app is compatible with.
<uses-feature>: The <uses-feature> element allows you to declare hardware and software
features your app needs
<manifest ... >
<uses-feature android:name="android.hardware.sensor.compass"
android:required="true" />
...
</manifest>
<uses-sdk>: To indicate the minimum version with which your app is compatible, your
manifest must include the <uses-sdk> tag and its minSdkVersion attribute.
Instead of <uses-sdk> tag we must specify minsdkversion and targetsdkversion in
build.gradle file
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial 70
Android
4.0 International License
Android Manifest file
android {
defaultConfig {
applicationId 'com.example.myapp'

// Defines the minimum API level required to


run the app.
minSdkVersion 15

// Specifies the API level used to test the app.


targetSdkVersion 28

...
}
}
Introduction to This work is licensed under a Creative
Android Developer Fundamentals Commons Attribution-NonCommercial 71
Android
4.0 International License
Android Manifest file
File conventions:This section describes the conventions and rules that
generally apply to all elements and attributes in the manifest file.

ElementsOnly the <manifest> and <application> elements are required. They


each must occur only once. Most of the other elements can occur zero or more
times.

AttributesTechnically, all attributes are optional. However, many attributes


must be specified so that an element can accomplish its purpose.

Except for some attributes of the root <manifest> element, all attribute names
begin with an android: prefix. For example, android:alwaysRetainTaskState

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 72
Android
4.0 International License
Android Manifest file
Multiple values:
If more than one value can be specified, the element is almost always
repeated, rather than multiple values being listed within a single element.

<intent-filter ... >


<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.INSERT" />
<action android:name="android.intent.action.DELETE" />
...
</intent-filter>

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 73
Android
4.0 International License
Android Manifest file
Resource values:
Resources are expressed as values with the following format:
"@[package:]type/name“

<activity android:icon="@drawable/smallPic" ... >

Example manifest file:


<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.example.myapp">

<!-- Beware that these values are overridden by the build.gradle file -->
Introduction to This work is licensed under a Creative
<uses-sdk android:minSdkVersion="15"
Android Developer Fundamentals android:targetSdkVersion="26"
Android
/>
Commons Attribution-NonCommercial 74
4.0 International License
Android Manifest file
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<!-- This name is resolved to com.example.myapp.MainActivity


based upon the package attribute -->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 75
Android
4.0 International License
Android Manifest file
<activity
android:name=".DisplayMessageActivity"
android:parentActivityName=".MainActivity" />
</application>
</manifest>

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 76
Android
4.0 International License
Challenges of Android development

● Multiple screen sizes and resolutions


● Performance: make your apps responsive and smooth
● Security: keep source code and user data safe
● Compatibility: run well on older platform versions
● Marketing: understand the market and your users

Introduction to This work is licensed under a Creative


Android Developer Fundamentals Commons Attribution-NonCommercial 77
Android
4.0 International License

You might also like