Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit1 and Unit2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 85

Video lecture 1 Content

History of Android OS

In October 2003, well before the term “smartphone” was used by most of the public,
and several years before Apple announced its first iPhone and its iOS, the company
Android Inc was founded in Palo Alto, California. Its four founders were Rich Miner,
Nick Sears, Chris White, and Andy Rubin.

Rubin was quoted as saying that Android Inc was going to develop “smarter mobile
devices that are more aware of its owner’s location and preferences.” In a 2013
speech in Tokyo that Android OS was originally meant to improve the operating
systems of digital cameras, as reported by PC World. The company made pitches to
investors in 2004 that showed how Android, installed on a camera, would connect
wirelessly to a PC. That PC would then connect to an “Android Datacenter,” where
camera owners could store their photos online on a cloud server. He further said “The
exact same platform, the exact same operating system we built for cameras, that
became Android for cellphones.”

In 2005, the next big chapter in Android’s history was made when the original
company was acquired by Google. Rubin and other founding members stayed on to
continue to develop the OS under their new owners. The decision was made to use
Linux as the basis for the Android OS, and that also meant that Android itself could
be offered to third-party mobile phone manufacturers for free. Google and the
Android team felt the company could make money offering other services that used
the OS, including apps.

In 2007, November Google started to reveal its plans to combat Apple and other
mobile platforms. It used the formation of what was called the Open Handset Alliance,
which included phone makers like HTC and Motorola, chip manufacturers such as
Qualcomm and Texas Instruments, and carriers including T-Mobile.

In Sept. 2008, the very first Android smartphone was announced, the T-Mobile G1,
also known as the HTC Dream in other parts of the world. It went on sale in the U.S.
Oct. of that year. The phone, with its pop-up 3.2-inch touchscreen combined with a
QWERTY physical keyboard, wasn’t exactly a design marvel.
Basics of Android OS/ Android I

Shashibala Surapaneni
Versions of Android
Versions of Android
Versions of Android
Contd...
Versions of Android

i. Android 1.1, released in Feb. 2009, didn’t have a public code name. However, it
reportedly used the internal name “Petit four”.The name refers to a French dessert.

ii. It was not until the launch of Android 1.5, just a few months later in April 2009,
that the OS version got its first public code name: “Cupcake.”

iii. The credit for naming Android versions after sweet candy and desserts has
traditionally gone to its project manager at Google, Ryan Gibson

iv. The now-familiar logo for the Android OS, which looks like a combination of a
robot and a green bug, was created by Irina Blok
Contd.....

1. It was not until the launch of Android 1.5, just a few months later in April 2009, that the OS version got its first
public code name: “Cupcake”. It added quite a few new features and improvements compared to the first two
public versions, including things that we now take for granted
a .such as the ability to upload videos to YouTube,
b. a way for a phone’s screen display to automatically rotate to the right positions, and
c. support for third-party keyboards.

2. Google quickly launched Android 1.6 Donut in Sept. 2009.


a.The new features included support for carriers that used CDMA-based networks. This allowed Android
phones to be sold by all carriers around the world.
b.Other features included the introduction of the Quick Search Box, and quick toggling between the
Camera,Camcorder and Gallery to streamline the media-capture experience.
c. Donut also introduced the Power Control widget for managing Wi-Fi, Bluetooth, GPS, etc.
Contd.....

i. In Oct. 2009, about a year after the launch of Android 1.0, Google released version 2.0 of the
OS, with the official code name Eclair. This version was the first to add text-to-speech support,
and also introduced live wallpapers, multiple account support, and Google Maps navigation,
among many other new features and improvements.

ii. The Motorola Droid was the first phone that included Android 2.0 out of the box. Motorola
continued to use the Droid brand for many of its phones as late as 2016.

iii. Launched in May 2010, Android 2.2 Froyo (short for “frozen yogurt”) was officially launched.
Smartphones with Froyo installed could take advantage of several new features, including Wi-Fi,
mobile hotspot functions, push notifications via Android Cloud to Device Messaging
(C2DM) service, flash support, and more.
Contd....
i. Android 2.3 Gingerbread, launched in Sept. 2010, is currently the oldest version of the OS that
Google still lists in its monthly platform version update page. As of Sept. 13 2017, Google
indicated that only 0.6 percent of all Android devices are currently running some version of
Gingerbread.

ii. The OS received a user interface refresh under Gingerbread. It added support for using near
field communication (NFC) functions for smartphones that had the required hardware. The first
phone to add both Gingerbread and NFC hardware was the Nexus S, which was co-developed by
Google and Samsung. Gingerbread also laid the groundwork for the selfie, by adding in support
for multiple cameras and video chat support within Google Talk.

iii. Android 3.0 Honeycomb.This version of the OS is perhaps the oddball of the bunch.
Honeycomb was released by Google for installation only on tablets and other mobile devices
with larger displays than current smartphones. It was first introduced in Feb. 2011, along with
the first Motorola Xoom tablet, and included features such as a redesigned UI specifically
for large screens, along with a notification bar placed on the bottom of a tablet’s display.

iv. The idea was that Honeycomb would offer specific features that could not be handled by the
smaller displays found on smartphones at the time. It was also a response by Google and its
third-party partners to the 2010 release of Apple’s iPad.
Contd....
i. Android 4.0 Ice Cream Sandwich Released in Oct. 2011, the Ice Cream Sandwich version of
Android brought a number of new features for users. It combined many of the features of the
tablet-only Honeycomb version with the smartphone-oriented Gingerbread. It also included
a “favorites tray” on the home screen, along with the first support for unlocking a phone by
using its camera to take a picture of its owner’s face. That kind of biometric sign-in support
has evolved and improved considerably since then.

ii. Other notable changes with ICS included support for all on-screen buttons, swipe gestures to
dismiss notifications and browser tabs, and the ability to monitor your data usage over
mobile and Wi-Fi.
Contd....
i. Android versions 4.1 to 4.3: Jelly Bean

ii. Spread across three impactful Android versions, 2012 and 2013's Jelly Bean releases took ICS's
fresh foundation and made meaningful strides in fine-tuning and building upon it. The releases
added plenty of poise and polish into the operating system and went a long way in making
Android more inviting for the average user.

iii. Android version 4.4: KitKat


iv. Late-2013's KitKat release marked the end of Android's dark era, as the blacks of Gingerbread
and the blues of Honeycomb finally made their way out of the operating system. Lighter
backgrounds and more neutral highlights took their places, with a transparent status bar and
white icons giving the OS a more contemporary appearance.

v. Android 4.4 also saw the first version of "OK, Google" support — but in KitKat, the hands-free
activation prompt worked only when your screen was already on and you were either at your
home screen or inside the Google app.
Contd....
i. Android versions 5.0 and 5.1: Lollipop

ii. Google essentially reinvented Android — again — with its Android 5.0 Lollipop release in the
fall of 2014. Lollipop launched the still-present-today Material Design standard, which brought a
whole new look that extended across all of Android, its apps and even other Google products.

iii. The card-based concept that had been scattered throughout Android became a core UI pattern —
one that would guide the appearance of everything from notifications, which now showed up on
the lock screen for at-a-glance access, to the Recent Apps list, which took on an unabashedly
card-based appearance.

iv. Lollipop introduced a slew of new features into Android, including truly hands-free voice
control via the "OK, Google" command, support for multiple users on phones and a priority
mode for better notification management.
Acknowledgements

1. https://www.wikitechy.com/tutorials/android/android-version-based-coding
2. https://www.quora.com/What-is-meant-by-an-Android-version
3. https://www.pcworld.com/article/3294787/android-9-pie-faq-features-tips.html
4. https://www.peerbits.com/blog/complete-guide-about-the-latest-android-q.html
5. https://en.wikipedia.org/wiki/Android_(operating_system)
6. https://en.wikipedia.org/wiki/Android_(operating_system)
Basics of Android OS/ Android I

Android Architecture

Shashibala Surapaneni
Android Architecture
Android Architecture
Android Architecture
Android architecture is a software stack of components to support mobile device needs. Android software stack
contains a Linux Kernel, collection of c/c++ libraries which are exposed through an application framework services,
runtime, and application.

Following are main components of android architecture those are

• Applications
• Android Framework
• Android Runtime
• Platform Libraries
• Linux Kernel

In these components, the Linux Kernel is the main component in android to provide its operating system functions to
mobile and Dalvik Virtual Machine (DVM) which is responsible for running mobile application.
Android Architecture
Android S/W Stack - Application

• Android provides a set of core applications:


• Email Client
• SMS Program
• Calendar
• Maps
• Browser
• Contacts
• Etc
Android S/W Stack - Application
Android S/W Stack - Application Framework

Android S/W Stack –App Framework

• Enabling and simplifying the reuse of components

• Developers have full access to the same framework APIs used by the core applications

• Users are allowed to replace components.


Android S/W Stack - Application Framework

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 strings,
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
Android S/W Stack - Application Framework
Android S/W Stack - Libraries

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


• Exposed to developers through the Android application framework
Android S/W Stack - Libraries

Core Libraries
• Providing most of the functionality available in the core libraries of the Java language
• APIs
• Data Structures
• Utilities
• File Access
• Network Access
• Graphics
• Etc
Android S/W Stack - Libraries
Android S/W Stack - Runtime

Dalvik Virtual Machine

• Providing environment on which every Android application runs


• Each Android application runs in its own process, with its own instance of the Dalvik VM.
• Dalvik has been written such that a device can run multiple VMs efficiently.
• 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
Android S/W Stack - Runtime
Android S/W Stack - Runtime
Android S/W Stack - Linux Kernel

Relying on Linux Kernel 2.6 for core system services

• Memory and Process Management


• Network Stack
• Driver Model
• Security
• Providing an abstraction layer between the H/W and the rest of the S/W stack
Android S/W Stack - Linux Kernel
Acknowledgements

1. https://www.wikitechy.com/tutorials/android/android-architecture
2. https://www.peerbits.com/blog/complete-guide-about-the-latest-android-q.html
3. https://www.tutorialspoint.com/android/android_architecture.htm
4. https://www.tutlane.com/tutorial/android/android-architecture
5. https://www.geeksforgeeks.org/android-architecture
6. https://www.learnvern.com/course/basics-of-android

Thank You
Basics of Android OS/ Android I

Android Setup

Shashibala Surapaneni
Android Setup

Set up the Android development environment

For Setting up Android development environment, You're required to have Windows XP or later, or Mac
OS X 10.5.8 or a later version to start Android application development process. Then, there are four tools
that you will need and they are available on the Internet for free:

Java JDK or JDK


Android SDK
Eclipse IDE for Java Developers
Android Development Tools (ADT) Eclipse Plugin
Android Setup

Step 1: Setup Java Development Kit (JDK)

You can download the JDK and install it. After that, you just have to set PATH and
JAVA_HOME variables to the folder where you have java and javac.

Note for Windows Users: If you installed the JDK in C:\jdk1.6.0_15 then you will have to add
the following two lines in your C:\autoexec.bat file.
set PATH=C:\jdk1.6.0_15\bin;%PATH%set JAVA_HOME=C:\jdk1.6.0_15
Android Setup

Step 2: Configure Android SDK


After you have successfully installed the Android SDK, it is time to configure it.

Step 3: Setup Eclipse IDE. Install the latest version of Eclipse. ...

Step 4: Setup Android Development Tools (ADT) Plugin. ...

Step 5: Create Android Virtual Device. ...

Write the Java code in Eclipse.


Android Setup

Installing the Eclipse Plugin

Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT). This plugin
provides a powerful, integrated environment in which to develop Android apps. It extends the capabilities of
Eclipse to let you quickly set up new Android projects, build an app UI, debug your app, and export signed (or
unsigned) app packages (APKs) for distribution.

If you need to install Eclipse, you can download it from eclipse.org/mobile.

Download the ADT Plugin


Start Eclipse, then select Help > Install New Software.
Click Add, in the top-right corner.
In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the
Location:
https://dl-ssl.google.com/android/eclipse/
Android Setup
Installing the Android SDK

Android Studio/Eclipse IDE, Google’s IDE for Android development, includes the Android SDK in its
installation and provides wizard options that simplify the management of the SDK platforms and tools that
you need.
Install Android Studio/Eclipse IDE, and the Android SDK that it includes, by downloading the installation file
from https://developer.android.com/studio/index.html or https://www.eclipse.org/downloads/packages/ .
The Android Developer’s website provides installation instructions for Windows, Mac, and Linux. See
https://developer.android.com/studio/install.html or https://www.eclipse.org/downloads/packages/ .

Installing the Eclipse Plugin

Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT). This plugin
provides a powerful, integrated environment in which to develop Android apps. It extends the capabilities of
Eclipse to let you quickly set up new Android projects, build an app UI, debug your app, and export signed (or
unsigned) app packages (APKs) for distribution.
Android Setup
If you need to install Eclipse, you can download it from eclipse.org/mobile.

Download the ADT Plugin


Start Eclipse, then select Help > Install New Software.
Click Add, in the top-right corner.
In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the
Location:
https://dl-ssl.google.com/android/eclipse/

The Android SDK provides:

• Tools that build and package your application into an .APK file (the file type that installs applications on
Android devices)

• An emulator to create Android Virtual Devices (AVD) where you can test your application if you do not
have access to a physical Android device

• An OEM USB driver to connect your development machine to a physical Android device through a USB
cable if you do have a device (enables you to deploy an application from your development machine to
the Android device)
Android Setup

Installing the Android ADT

Android Development Tools (ADT) is a plugin for the Eclipse IDE that is designed to give you a powerful,
integrated environment in which to build Android applications.

ADT extends the capabilities of Eclipse to let you quickly set up new Android projects, create an application
UI, add components based on the Android Framework API, debug your applications using the Android SDK
tools, and even export signed (or unsigned) APKs in order to distribute your application.

Developing in Eclipse with ADT is highly recommended and is the fastest way to get started. With the guided
project setup it provides, as well as tools integration, custom XML editors, and debug ouput pane, ADT gives
you an incredible boost in developing Android applications.

This document provides step-by-step instructions on how to download the ADT plugin and install it into your
Eclipse development environment. Note that before you can install or use ADT, you must have compatible
versions of both the Eclipse IDE and the Android SDK installed. For details, make sure to read Installing the
ADT Plugin,
Android Setup

Creating an Android Virtual Device

An Android Virtual Device (AVD) replicates an Android device on your development computer. It is a useful
option for testing, especially if you only have access to one or a limited range of physical Android devices.

The AVD Manager that you launch from Android Studio by clicking Tools then Android, and then AVD
Manager has a range of ready-to-use virtual devices. It includes most of those devices developed by Google
itself, such as the Nexus and Pixel XL range. Google maintains documentation describing how to manage
AVDs (see https://developer.android.com/studio/run/managing-avds.html).

Other Android device vendors, such as Samsung, provide specifications on their websites that you can use to
create the AVD yourself.
Android Setup
To create an AVD:

In Android Studio, launch the Android Virtual Device Manager by selecting Tools, then Android, and then AVD
Manager.

In the Your Virtual Devices screen, click Create Virtual Device.

In the Select Hardware screen, select a phone device, such as Pixel, and then click Next.

In the System Image screen, click Download for one of the recommended system images. Agree to the terms
to complete the download.

After the download completes, select the system image from the list and click Next.

On the next screen, leave all the configuration settings unchanged and click Finish.

In the Your Virtual Devices screen, select the device you just created and click Launch this AVD in the
emulator.
Android Setup

Link for installing Android using ECLIPSE

https://www.youtube.com/watch?v=47yY1uCTU0M
Acknowledgements

1. https://docs.oracle.com/middleware/maf250/mobile/install/setting-development-tools-android-
platform.htm#MAFIG-GUID-D7837827-5849-4927-A742-FBAC0147B295

2. http://www.dre.vanderbilt.edu/~schmidt/android/android-4.0/out/target/common/docs/doc-comment-
check/sdk/eclipse-adt.html

3.https://stuff.mit.edu/afs/sipb/project/android/docs/sdk/installing/installing-adt.html

4. https://dl-ssl.google.com/android/eclipse/

Thank you
Basics of Android OS/ Android I

Application Components

Shashibala Surapaneni
Create Android Application
The first step is to create a simple Android Application using Android studio. When you click
on Android studio icon, it will show screen as shown below
You can start your application development by calling start a new android studio project. in a new
installation frame should ask Application name, package information and location of the project.−
After entered application name, it going to be called select the form factors your application runs on, here need to
specify Minimum SDK, in our tutorial, I have declared as API23: Android 6.0(Mashmallow) −
The next level of installation should contain selecting the activity to mobile, it specifies the default layout for
Applications.
At the final stage it going to be open development tool to write the application code.
Anatomy of Android Application

Before you run your app, you should be aware of a few directories and files in the Android project

Anatomy of Android Application
Before you run your app, you should be aware of a few directories and files in the
Android project −

Sr.No. Folder, File & Description

JavaThis contains the .java source files for your project. By default, it includes an MainActivity.java
1 source file having an activity class that runs when your app is launched using the app icon.

res/drawable-hdpiThis is a directory for drawable objects that are designed for high-density screens.
2

res/layoutThis is a directory for files that define your app's user interface.
3

res/valuesThis is a directory for other various XML files that contain a collection of resources, such as
4 strings and colours definitions.

AndroidManifest.xmlThis is the manifest file which describes the fundamental characteristics of the
5 app and defines each of its components.

Build.gradleThis is an auto generated file which contains compileSdkVersion, buildToolsVersion,


6 applicationId, minSdkVersion, targetSdkVersion, versionCode and versionName
Following section will give a brief overview of the important application files.

1. The Main Activity File

The main activity code is a Java file MainActivity.java. This is the actual application file which
ultimately gets converted to a Dalvik executable and runs your application. Following is the default
code generated by the application wizard for Hello World! application −

package com.example.helloworld;
import android.support.v7.app.AppCompatActivity;import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}}

Here, R.layout.activity_main refers to the activity_main.xml file located in the res/layout folder. The
onCreate() method is one of many methods that are figured when an activity is loaded.
2. The Manifest File

Whatever component you develop as a part of your application, you must declare all its components in a manifest.xml which resides at the root of
the application project directory. This file works as an interface between Android OS and your application, so if you do not declare your component
in this file, then it will not be considered by the OS. For example, a default manifest file will look like as following file −
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorialspoint7.myapplication">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
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>
Here <application>...</application> tags enclosed the components related to the application. Attribute android:icon will point to the application
icon available under res/drawable-hdpi. The application uses the image named ic_launcher.png located in the drawable folders
The <activity> tag is used to specify an activity and android:name attribute specifies the fully qualified class name of the Activity subclass and the
android:label attributes specifies a string to use as the label for the activity. You can specify multiple activities using <activity> tags.
The action for the intent filter is named android.intent.action.MAIN to indicate that this activity serves as the entry point for the application. The
categoryfor the intent-filter is named android.intent.category.LAUNCHER to indicate that the application can be launched from the device's
launcher icon.
The @string refers to the strings.xml file explained below. Hence, @string/app_name refers to the app_name string defined in the strings.xml file,
which is "HelloWorld". Similar way, other strings get populated in the application.
Following is the list of tags which you will use in your manifest file to specify different Android application
components −

· <activity>elements for activities

· <service> elements for services

· <receiver> elements for broadcast receivers

· <provider> elements for content providers


3. The Layout File

The activity_main.xml is a layout file available in res/layout directory, that is referenced by your application
when building its interface. You will modify this file very frequently to change the layout of your application.
For your "Hello World!" application, this file will have following content related to default layout −
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>

This is an example of simple RelativeLayout which we will study in a separate chapter. The TextView is an
Android control used to build the GUI and it have various attributes like android:layout_width,
android:layout_height etc which are being used to set its width and height etc.. The @string refers to the
strings.xml file located in the res/values folder. Hence, @string/hello_world refers to the hello string defined in
the strings.xml file, which is "Hello World!".
The Strings File

The strings.xml file is located in the res/values folder and it contains all the text that your application uses.
For example, the names of buttons, labels, default text, and similar types of strings go into this file. This file is
responsible for their textual content. For example, a default strings file will look like as following file −

<resources>
<string name="app_name">HelloWorld</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string></resources>
Running the Application

Let's try to run our Hello World! application we just created. I assume you had created your AVD while doing environment
set-up. To run the app from Android studio, open one of your project's activity files and click Run icon from the tool bar.
Android studio installs the app on your AVD and starts it and if everything is fine with your set-up and application, it will display
following Emulator window −

Congratulations!!! you have developed your first Android Application and now just keep following rest of the tutorial step by
step to become a great Android Developer. All the very best.
Thank You
Basics of Android OS/ Android I

Application Components

Shashibala Surapaneni
Application Components
Android Apps are written in Java. The Android SDK tools compile the code, data and
resource files into an APK (Android package). Generally, one APK file contains all
the content of the app.

Each app runs on its own virtual machine(VM) so that app can run isolated from
other apps.

Android system works with the principle of least privilege. Each app only has access
to the components which it requires to do its work, and no more.

However, there are ways for an app to share data with other apps, such as by sharing
Linux user id between app, or apps can request permission to access device data like
SD card, contacts etc.
Application Components
App Components

App components are the building blocks of an Android app.

Each components plays a specific role in an Android app which serves a distinct
purpose and has distinct life-cycles(the flow of how and when the component is
created and destroyed).

Here are the four types of app components:


Application Components
App Components

1. Activities: An activity represents a single screen with a User Interface(UI).

An Android app may have more than one activity. (e.g. an email app might have one
activity to list all the emails, another to show the contents of each email, and another
to compose new email.)

All the activities in an App work together to create a User eXperience (UX).
Application Components
App Components

2. Services:

A service runs in the background to perform long-running operations or to perform


work for a remote processes.

A service does not provide any UI, it runs only in the background with the User's
input. (e.g. a service can play music in the background while the user is in a different
App, or it might download data
Application Components
App Components
3. Content Providers: A content provider manages shared app data. There are four
ways to store data in an app:
it can be written to a file and stored in the file system, inserted or updated to a
SQLite database, posted to the web,

or saved in any other persistent storage location the App can access. Through content
providers,
other Apps can query or even modify the data. (e.g. Android system provides a
content provider that manages the user's contact information so that any app which
has permission can query the contacts.)

Content providers can also be used to save the data which is private to the app for
better data integrity.
Application Components
App Components

Broadcast receivers:
A broadcast receiver responds to the system-wide broadcasts of announcements (e.g.
a broadcast announcing that the screen has turned off, the battery is low, etc.) or from
Apps (e.g. to let other apps know that some data has been downloaded to the device
and is available for them to use).

Broadcast receivers don't have UIs but they can show notifification in the status bar
to alert the user. Usually broadcast receivers are used as a gateway to other
components of the app, consisting mostly of activities and services.
Application Components
App Components

One unique aspect of the Android system is that any app can start another app's
component (e.g. if you want to make call, send SMS, open a web page, or view a
photo, there is an app which already does that and your app can make use of it,
instead of developing a new activity for the same task).

When the system starts a component, it starts the process for that app (if it isn't
already running, i.e. only one foreground process per app can run at any given time
on an Android system) and instantiates the classes needed for that component.

Thus the component runs on the process of that App that it belongs to.
Application Components
App Components

Therefore, unlike apps on other systems, Android apps don't have a single entry
point(there is no main() method).

Because the system runs each app in a separate process, one app cannot directly
activate another app's components, however the Android system can.

Thus to start another app's component, one app must send a message to the system
that specifies an intent to start that component, then the system will start that
component.
Thank You
Activity in Android
• Activity - represents the presentation layer of an Android application
– screen which the user sees.
• Activity is a Java code that supports a screen or UI.
– building block of the user interface is the activity.
• Activity class is a pre-defined class in Android and every
application which has UI must inherit it to create window.
• An Android application can have several activities and it can
be switched between them during runtime of the application.
Problem
• Write an android app for displaying current time.
– Use text view to display time.
– Time must be seen when the activity first seen by user
MainActivity.Java
import android.widget.TextView;
import java.util.Date;
public class MainActivity extends Activity
{ @Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txtView=(TextView)findViewById(R.id.textView);
txtView.setText(new Date().toString());
}
}

Will this clock keep Ticking???


Activity LifeCycle
onCreate()
• onCreate() is called when your Activity is getting created for the
first time.
• It is called only once during the entire Activity Lifecycle.
• One of the important things you are supposed to do is to set
the Activity Layout through setContentView ()function.
• You can use onCreate to initialize your variables.
• In any Android application, whenever you create an Activity, the
minimum method which you need to override is onCreate().
onCreate()
class MainActivity extends Activity
{ @Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

• Bundle is typically used to store the state of your Activity.


• Take the example of screen rotation, during which your Activity
gets killed and OnCreate is called again.
– You can determine if the Activity was already there using Bundle so that
you do not have to create the Activity again.
onStart()

• onStart gets called just before


the Activity becomes visible
to the user.
• Note:onStart is called
from two places –
– after onRestart and
– OnCreate
• onStart is always followed
by OnResume or OnStop.
• You can use onStart to
reset Activity data,
reinitialize variables etc
onResume()

• onResume gets called when your Activity comes into the foreground,
and it becomes visible to the user.
– At this point, the Activity is on top of the Activity stack, and the user can
start interacting with the Activity.
• onResume is typically used to register Listeners, bind to Services etc.
• onResume is a good place to refresh your UI with any new changes
which might have occurred during the period in which the Activity
was not visible.
– For example, if you are polling a Service in the background (like checking
for new tweets), onResume is a good place to update your screen with
new results.
onPause()
• onPause is called when another android activity comes on top of
your Activity.
– Typically anything that steals your user away from your Activity will result
in onPause.
• In OnPause, we either release the resources, or save the
application data, or stop background threads etc.
• It is always guaranteed that whenever your Activity is
becoming invisible or partially invisible, onPause will be called.
• Note: once onPause is called, Android reserves the right to kill your
Activity at any point. Hence you should not be relying on receiving
any further events.
onStop()

• onStop is called when your Activity is no longer visible to the user, it is


similar to onPause but here you will not see your android activity entirely.
• You can use this method as well to store the state of your application
and shut down time intensive or CPU intensive operations.
• So what is the difference between onPause and OnStop ?
– If an Activity comes into the foreground and fills the screen such that your
current activity is not at all visible, your current android activity will be
called with both onPause and onStop .
– If, however, an Activity that comes to foreground does not fill the screen and
your current Activity is partially visible, your current Activity will be called
with only onPause.
• Typically whenever you see a dialog box which requires your attention
like battery low, network connection your current android activity
becomes partially visible and popup box comes on the top. This is the point
where only onPause will be called.
onRestart()
• It is similar to onCreate, but onRestart gets called only after onStop.
– This is the method which you can use to know if your application is
starting afresh or getting restarted.
• In onRestart, you will get your application to save the state
and reinitialize all the variables. onStart gets called after this.
onDestroy()

• This is the method which will be called when your Activity is


getting killed.
• This is the final call the Activity will receive in its Lifecycle.
• When the user press back button on any Activity the foreground
activity gets destroyed and control will return to the previous Activity.
• There is no guaranty that onDestroy will be called.
– Only when the system is low on resources or user press the back button or
if you use finish() explicitly in your code, onDestroy gets called.
• Even though you should always use onPause and onStop to clean up
resources, release connections etc; onDestory is there to let your
app have the final chance to clean things up before the Activity cease
to exist.
References
• http://developer.android.com/reference/android/app/Activity.ht
ml
• http://www.codelearn.org/android-tutorial/android-activity
Additional Components
There are additional components which will be used in the construction of
above mentioned entities, their logic, and wiring between them. These
components are −

S.No Components & Description

Fragments
1 Represents a portion of user interface in an Activity.

Views
2 UI elements that are drawn on-screen including buttons, lists forms etc.

Layouts
3 View hierarchies that control screen format and appearance of the views.

Intents
4 Messages wiring components together.

Resources
5 External elements, such as strings, constants and drawable pictures.

Manifest
6 Configuration file for the application.

Widgets
7 Small Application Views

You might also like