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

Android Chapter-2

The document provides an overview of Android architecture, detailing its five main components: Linux Kernel, Native Libraries, Android Runtime, Application Framework, and Applications. It also explains the Android Activity Lifecycle, including the seven key methods that manage activity states, as well as the structure of an Android application, highlighting essential folders and files. Additionally, it covers important Android terminologies and the concept of Intents, including their types and usage in application development.

Uploaded by

ritenpanchasara
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)
6 views

Android Chapter-2

The document provides an overview of Android architecture, detailing its five main components: Linux Kernel, Native Libraries, Android Runtime, Application Framework, and Applications. It also explains the Android Activity Lifecycle, including the seven key methods that manage activity states, as well as the structure of an Android application, highlighting essential folders and files. Additionally, it covers important Android terminologies and the concept of Intents, including their types and usage in application development.

Uploaded by

ritenpanchasara
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/ 33

SHREE SWAMI VIVEKANAND COLLEGE

SURENDRANAGAR

Chapter :-2 Introduction to Android and Android Application Design

Architecture of Android.

 Android architecture is a stack of software components. It is in the


form of a software application, operating system, run-time
environment,middleware, native libraries and services.

 It is categorized into five parts as below:


 Linux Kernel
 Native Libraries
 Android Runtime
 Application Framework
 Applicatioin

 The following diagram shows the architecture of Android.

1|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

1. Linux Kernel:-

 Linux is the heart of Android architecture.

 It provides a level of abstraction between the hardware


devices and the upper layers of the Android software stack.

 The Android operating system is based on the Linux kernel.

 The Linux kernel is responsible for various device drivers such


as Camera driver, Display driver, Bluetooth driver, Keypad
driver, Memory management, Process management, Power
management, etc.

2. Native Libraries:-
 The native libraries such as Media, WebKit, SQLite, OpenGL,
Free Type, C Runtime library (libc) etc. are situated on the top
of a Linux kernel.

 Media library is responsible for playing and recording audio


and video formats, Free Type is for font support, WebKit is for
browser support,SQLite is for database, SSL is for Internet
security etc.

3. Android Runtime:-
 Android Runtime is the third section of the architecture and
situated on the second layer from the bottom.

 Android Runtime includes core libraries and Dalvik Virtual


Machine(DVM) which is responsible to run android
application.

2|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

 Dalvik Virtual Machine (DVM) is like Java Virtual Machine


(JVM) in Java, but DVM is optimized for mobile Devices.

 DVM makes use of the Linux core features like memory


management and multi-threading, which are essential in the
Java language.

 DVM provides fast performance and consumes less memory.

4. Application Framework:-

 Application framework is situated on the top of the Native


libraries and Android runtime.

 Android framework provides a lot of classes and interfaces for


Android application development and higher level services to
the applications inthe form of Java classes.

 It includes Android API's such as Activity manager, Window


manager,Content Provider, Telephony Manager, etc.

 Activity manger is responsible for controlling all the aspects


of the application lifecycle and activity stack, Content
provider is responsible for allowing the applications to publish
and share the data with the other applications, View system
is responsible for creating application user interfaces, etc.

5. Applications:-

 Applications are situated on the top of the Application


framework.

3|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

 The applications such as Home, Contact, Alarm, Calender,


Camera, Browsers, etc. use the Android framework which
uses Android runtime and libraries. Android runtime and
Native libraries use Linux kernel.

 The user can write his/her application to be installed on this


layer only.

Android Activity Life Cycle

4|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

 Android Activity Lifecycle is a collection of methods exposed within


the Activity class which provides the developer a resource
management framework. The resource management framework
allows developers to meet the unique state management
requirements of each activity and handle the resource
management.

 This lifecycle is controlled by seven methods of


android.app.Activity.class.

 An Activity is a screen which contains the user interface.


User can interact with these activities to perform some task such
as send an email, send messages or taking the photo.
 The above figure shows the seven methods of an Android
activity lifecycle. When you run your application, an Activity goes
through the different states.

 These seven activities describes how activity will behave at


different states.

 The main purpose of an activity is to interact with the user.

 It is the single screen in android and is like a window or frame of


Java With the help of activity, user can place all the UI
components or widgets in a single screen.

 Following are the seven callback methods of Android Activity


Lifecycle which are called by the system,

5|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

(1) OnCreate()

This method is called when activity is created. It is used toinitialize the


activity.

(2) OnStart()
This method is called when activity becomes visible to the user.

(3) OnResume()
it is called by the system after OnCreate() method is fnished. This method
is called when activity will start interacting with the user.

(4) OnPause()
It is used to initialize fields, register listeners, bind to services etc .This
method is called when current activity is being paused and the previous activity
is being resumed.

(5) OnStop()
This method is called when activity is no longer visible to the user.

(6) OnRestart()
This method is called after your activity has stopped and restarting.

(7) OnDestroy()
This method is called before the activity is destroyed.

6|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

States of an Activity

(1) Running :-

This state defines that the activity is visible and interacts with the user.

(2) Paused :-

This state defines that the activity is still visible but partially hidden and the
instance is running but might be killed by the system.

(3) Stopped:-

This state defines that the activity is not visible and the instance is running
but might be killed by the system.

(4) Killed :-

This state defines that the activity has been terminated by the system call
to its finish() method.

7|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

Structure of Android Application.

8|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

The above diagram shows the basic building blocks of an Android application.
Android application in Eclipse or in any development tool have a pre-defined
structure with code and resource organized into a number of folders.

Every Android project contains several folders, like:

Folder Name Description

Src The 'src' stands for Source Code. It contains the Java Source
files.

Gen The 'gen' stands for Generated Java Library. This library is
for Android internal use only.

Android 2.2 The Android Framework Library is stored here.

Assets It is used to store raw asset files.

Libs It contains private libraries.

res The 'res' stands for Resource file. It can store resource files such
as pictures, XML files, etc. It contains some additional folders
such as Drawable, Layout and Values.

anim: It is used for XML files that are compiled into animation
objects.
color: It is used for XML files that describe colors.
drawable: It is used to store various graphics files. In Android
project structure,

there are three types of drawable folders,


1. drawable-mdpi
2. drawable-hdpi
3. drawable-ldpi

9|Page
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

The above drawable folders are required in order to adapt to


different screen resolutions.

layout: It is used for placing the XML layout files, which defines
how various Android objects such as textbox, buttons, etc. are
organized on the screen.

menu: It is used for defining the XML files in the application


menu.

raw: The 'raw' stands for Raw Asset Files. These files are
referenced from the application using a resource identifier in
the R class.
For example, good place for media is MP3 or Ogg files.

values: It is used for XML files which stores various string values,
such as titles, labels, etc.

xml: It is used for configuring the application components.

AndroidManifest.xml This file indicates the Android definition file. This file contains
the information about the Android application such as minimum
Android version, permission to access Android device
capabilities such as Internet access permission, phone
permission etc.

10 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

default.properties This file contains the project settings, such as build the target.
Do not edit this file manually. It should be maintained in a
Source Revision Control System.

MainLayout.xml This file describes the layout of the page. So all the components
such as textboxes, labels, radio buttons, etc. are displaying on
the application screen.

Activity class The application occupies the entire device screen which needs
at least one class inherits from the Activity class. OnCreate()
method initiates the application and loads the layout page.

11 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

Android terminologies

1. XML

In Android, XML is used for designing the application’s UI like


creating layouts, views, buttons, text fields etc. and also used in
parsing data feeds from the internet.

2. View

A view is an UI which occupies rectangular area on the screen to


draw and handle user events.

3. Layout

Layout is the parent of view. It arranges all the views in a proper


manner on the screen.

4. Activity

An activity can be referred as your device’s screen which you see.


User can place UI elements in any order in the created window of
user’s choice.

5. Emulator

An emulator is an Android virtual device through which you can


select the target Android version or platform to run and test your
developed application.

12 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

6. Manifest file

Manifest file acts as a metadata for every application. This file


contains all the essential information about the application like app
icon, app name, launcher activity, and required permissions etc.

7. Service

Service is an application component that can be used for long-


running background processes. It is not bounded with any activity as
there is no UI. Any other application component can start a service
and this service will continue to run even when the user switches
from one application to another.

8. Broadcast Receiver

Broadcast Receiver is another building block of Android application


development which allows you to register for system and
application events. It works in such a way that, when the event
triggers for the first time all the registereIntent is a messaging object
which can be used to communicate between two or more
components like activities, services, broadcast receiver etc. Intent
can also be used to start an activity or service or to deliver a
broadcast messages.

9. Content Providers

Content Providers are used to share data between two applications.


This can be implemented in two ways:

1. When you want to implement the existing content provider in


another application.
2. When you want to create a new content provider that can share
its data with other applications

13 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

10.Intent

Intent is a messaging object which can be used to communicate


between two or more components like activities, services, broadcast
receiver etc. Intent can also be used to start an activity or service or
to deliver a broadcast messages.

What is intent? Explain types of intent with example.

Android Intent is a messaging object used to request another app


component to perform an action. Intent facilitates users to communicate with app
component through several ways such as starting an activity, starting a service,
delivering a broadcast receiver, etc.

Android intents are mainly used to:

o Start the service


o Launch an activity
o Display a web page
o Display a list of contacts
o Broadcast a message
o Dial a phone call etc.

Types of Android Intents

There are two types of intents available in android, those


are Implicit Intents and Explicit Intents.

14 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

(1) Explicit Intent:


This intent satisfies the request within the application component. It takes the
fully qualified class name of activities or services that we want to start.

Kotlin Android Explicit Intent Example

In this example, we will call the other activity class from another activity class using
explicit intent. Using intent, we will send the data from the first activity class to second
activity class. Second activity class gets this data and displays them in toast message.

15 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

Add the following code in the activity_main.xml.

<?xml version="1.0" encoding="utf8"?>


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.
android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.intent.com.kotlinexplicitintent.MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="First Activity"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.172" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"

16 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

android:text="Click"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.77" />

</android.support.constraint.ConstraintLayout>

MainActivity.kt

package example.intent.com.kotlinexplicitintent

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {


val id:Int = 10
val language:String = "kotlin"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

button.setOnClickListener() {
intent = Intent(this, SecondActivity::class.java)
intent.putExtra("id_value", id)
intent.putExtra("language_value", language)
startActivity(intent)
}
}
}

17 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

Create another activity class named as SecondActivity.

second_activity.xml
In the second_activity.xml file add the following code.

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


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.and
roid.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.intent.com.kotlinexplicitintent.SecondActivity">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="SecondActivity"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.107" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"

18 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="back"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.774" />
</android.support.constraint.ConstraintLayout>

SecondActivity.kt

package example.intentt.com.kotlinexplicitintent

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_second.*

class SecondActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {


super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)

val bundle:Bundle = intent.extras


val id = bundle.get("id_value")
val language = bundle.get("language_value")
Toast.makeText(applicationContext,id.toString()+" "+language,Toast.LEN
GTH_LONG).show()
button2.setOnClickListener(){
intent = Intent(this,MainActivity::class.java)
startActivity(intent)

19 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

}
}
}

(2) Implicit Intent:


This intent does not specify the component name. It invokes the component of
another app to handle it.

For example, if we want to share data using Intent, it invokes the relevant component to
fulfill the request.

20 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

Kotlin Android Implicit Intent Example Invoking URL

In this example, we will invoke the URL using Implicit Intent clicking on Button.

activity_main.xml
Add the following code in activity_main.xml file. In this activity, we use a Button to
invoke Intent.

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


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.and
roid.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

21 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

android:layout_height="match_parent"
tools:context="example.intent.com.kotlinimplicitintent.MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="Your First Activity"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.172" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="click to invoke intent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.77" />

</android.support.constraint.ConstraintLayout>

22 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

MaiActivity.kt
Add the following code in the MainActivity.kt class. In this class, we are invoking the
URL on clicking the button using Implicit Intent. To invoke this intent, we are passing
the action type and URL. The startActivity() method is used to start the Intent.

package example.intent.com.kotlinimplicitintent

import android.content.Intent
import android.net.Uri
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {


super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

button.setOnClickListener(){
intent = Intent(Intent.ACTION_VIEW)
intent.setData(Uri.parse("https://www.google.com/"))
startActivity(intent)
/* intent= Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.
com/"))
startActivity(intent)*/
}
}
}

23 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

Intent Filter in Android with Demo App

intent Filter
 Implicit intent uses the intent filter to serve the user request.
 The intent filter specifies the types of intents that an activity,
service, or broadcast receiver can respond.
 Intent filters are declared in the Android manifest file.
 Intent filter must contain <action>

Most of the intent filter are describe by its


1. <action>,
2. <category> and
3. <data>.

activity_main.xml file.

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

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<Button

android:id="@+id/sendButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="SEND"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.476"

24 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintVertical_bias="0.153" />

<Button

android:id="@+id/buttonView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="View"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.498"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.826" />

</androidx.constraintlayout.widget.ConstraintLayout>

AndroidManifest.xml File.

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.menuapplication">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

25 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

android:theme="@style/Theme.MenuApplication">

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

<!--SEND INTENT FILTER-->

<intent-filter>

<action android:name="android.intent.action.SEND"/>

<category android:name="android.intent.category.DEFAULT"/>

<data android:mimeType="text/plain"/>

</intent-filter>

<!--VIEW INTENT FILTER-->

<intent-filter>

<action android:name="android.intent.action.VIEW"/>

<category android:name="android.intent.category.DEFAULT"/>

<category android:name="android.intent.category.BROWSABLE"/>

<data android:scheme="http"/>

</intent-filter></activity></application></manifest>

26 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

MainActivity.kt file

package com.example.intentfilter

import android.content.Intent

import android.os.Bundle

import androidx.appcompat.app.AppCompatActivity

import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

// send button on click listener

sendButton.setOnClickListener {

var intent = Intent(Intent.ACTION_SEND) // intent

intent.type = "text/plain"

intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]")

intent.putExtra(Intent.EXTRA_SUBJECT, "This is a dummy message")

intent.putExtra(Intent.EXTRA_TEXT, "Dummy test message")

startActivity(intent)

27 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

// View on click listener

buttonView.setOnClickListener {

var intent = Intent(Intent.ACTION_VIEW)

startActivity(intent)

Android BroadcastReceiver

Android BroadcastReceiver is a dormant component of android that listens


to system-wide broadcast events or intents.

When any of these events occur it brings the application into action by
either creating a status bar notification or performing a task.

Unlike activities, android BroadcastReceiver doesn’t contain any user interface.


Broadcast receiver is generally implemented to delegate the tasks to
services depending on the type of intent data that’s received.

Following are some of the important system wide generated intents.

1. android.intent.action.BATTERY_LOW : Indicates low battery


condition on the device.
2. android.intent.action.BOOT_COMPLETED : This is broadcast once,
after the system has finished booting
3. android.intent.action.CALL : To perform a call to someone specified
by the data
4. android.intent.action.DATE_CHANGED : The date has changed
5. android.intent.action.REBOOT : Have the device reboot
6. android.net.conn.CONNECTIVITY_CHANGE : The mobile network or
wifi connection is changed(or reset)

28 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

Resource types

Each page in this section describe the usage, format, and syntax for a certain type
of app resource that you can provide in your project resources directory ( res/).

Here's a brief summary of each page:

Animation Resources

Define pre-determined animations.


Tween animations are saved in res/anim/ and accessed from the R.anim class.
Frame animations are saved in res/drawable/ and accessed from
the R.drawable class.

Color State List Resource

Define a color resources that changes based on the View state.


Saved in res/color/ and accessed from the R.color class.

Drawable Resources

Define various graphics with bitmaps or XML.


Saved in res/drawable/ and accessed from the R.drawable class.

Layout Resource

Define the layout for your application UI.


Saved in res/layout/ and accessed from the R.layout class.

Menu Resource

Define the contents of your application menus.


Saved in res/menu/ and accessed from the R.menu class.

String Resources

Define strings, string arrays, and plurals (and include string formatting and styling).
Saved in res/values/ and accessed from the R.string, R.array, and R.plurals classes.

Style Resource

Define the look and format for UI elements.


Saved in res/values/ and accessed from the R.style class.

29 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

Font Resources

Define font families and include custom fonts in XML.


Saved in res/font/ and accessed from the R.font class.

More Resource Types

Define other primitive values as static resources, including the following:

Bool

XML resource that carries a boolean value.

Color

XML resource that carries a color value (a hexadecimal color).

Dimension

XML resource that carries a dimension value (with a unit of measure).

ID

XML resource that provides a unique identifier for application resources and
components.

Integer

XML resource that carries an integer value.

Integer Array

XML resource that provides an array of integers.

Typed Array

XML resource that provides a TypedArray (which you can use for an array of
drawables).

AndroidManifest.xml file in android


The AndroidManifest.xml file contains information of your package, including
components of the application such as activities, services, broadcast receivers, content
providers etc.

30 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

It performs some other tasks also:

o It is responsible to protect the application to access any protected parts by


providing the permissions.
o It also declares the android api that the application is going to use.
o It lists the instrumentation classes. The instrumentation classes provides profiling
and other informations. These informations are removed just before the application is
published etc.

This is the required xml file for all the android application and located inside the root
directory.

A simple AndroidManifest.xml file looks like this:

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

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

31 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

</manifest>

Elements of the AndroidManifest.xml file


The elements used in the above xml file are described below.

<manifest>

manifest is the root element of the AndroidManifest.xml file. It has package attribute
that describes the package name of the activity class.

<application>

application is the subelement of the manifest. It includes the namespace declaration.


This element contains several subelements that declares the application component
such as activity etc.

The commonly used attributes are of this element are icon, label, theme etc.

android:icon represents the icon for all the android application components.

android:label works as the default label for all the application components.

android:theme represents a common theme for all the android activities.

<activity>

activity is the subelement of application and represents an activity that must be


defined in the AndroidManifest.xml file. It has many attributes such as label, name,
theme, launchMode etc.

android:label represents a label i.e. displayed on the screen.

android:name represents a name for the activity class. It is required attribute.

<intent-filter>

intent-filter is the sub-element of activity that describes the type of intent to which
activity, service or broadcast receiver can respond to.

32 | P a g e
Prepared By : Bhartiba Parmar
SHREE SWAMI VIVEKANAND COLLEGE
SURENDRANAGAR

<action>

It adds an action for the intent-filter. The intent-filter must have at least one action
element.

<category>

It adds a category name to an intent-filter.

33 | P a g e
Prepared By : Bhartiba Parmar

You might also like