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

Unit-3

The document provides an overview of Android as an operating system and programming platform developed by Google, detailing its architecture, core applications, and development tools. It covers essential components like activities, intents, and fragments, along with their lifecycles and interactions within the Android environment. Additionally, it outlines the setup requirements for Android development and the evolution of various Android platform versions.

Uploaded by

karmjoshi992
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Unit-3

The document provides an overview of Android as an operating system and programming platform developed by Google, detailing its architecture, core applications, and development tools. It covers essential components like activities, intents, and fragments, along with their lifecycles and interactions within the Android environment. Additionally, it outlines the setup requirements for Android development and the evolution of various Android platform versions.

Uploaded by

karmjoshi992
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Mobile Application Development (MAD)

GTU # 3170726

Android Operating System


Introduction to Android
 Android is an Operating System and programming platform developed by Google.
 It supports devices like mobile phones and other devices, such as tablets, watch, TV, & auto.
 Android includes a Software Development Kit (SDK) that helps you write code and assemble
software modules to create apps for Android users.
 Android also provides a marketplace (Play Store) to distribute apps.
 It conquered around 75% of the global market share by the end of 2020.
 The company named Open Handset Alliance developed Android for the first time that is based
on the modified version of the Linux kernel and other open-source software.
 Google sponsored the project at initial stages and in the year 2005, it acquired the whole
company.
 In September 2008, the first Android-powered device launched in the market.
Android System With Architecture
Android comes with a set of
core applications such as
Contacts, Calendar, Maps, and a
browser

You use these APIs to control what your


app looks like and how it behaves

The Android runtime comes with a set


You can access OpenGL ES through
of core libraries that implement most
the native C/C++ libraries to add
of the Java programming language.
support for drawing and manipulating
Each Android app runs in its own
2D and 3D graphics in your app
process.
HAL provides an interfaces that
expose device hardware capabilities to
the higher-level Java API framework.
Underneath everything else lies the Linux
kernel. Android relies on the kernel for
drivers, and also core services such as
security and memory management.
System Apps
 System apps are pre-installed apps in the system partition with your ROM.
 System app is simply an app placed under ‘/system/app‘ folder on an Android device.
 ‘/system/app’ is a read-only folder.
 Android device users do not have access to this partition. Hence, users cannot directly install
or uninstall apps to/from it.
 Apps such as camera, settings, messages, Google Play Store, etc.
Java Api Framework
 The entire feature-set of the Android OS is available using APIs written in the Java language.
 These APIs form the building blocks you need to create Android apps by simplifying the reuse
of core, modular system components and services.
 A rich and extensible View System you can use to build an app’s UI, including lists, grids, text
boxes, buttons, and even an embeddable web browser.
 A Resource Manager, providing access to non-code resources such as localized strings,
graphics, and layout files.
 A Notification Manager that enables all apps to
display custom alerts in the status bar.
 An Activity Manager that manages the lifecycle of
apps and provides a common navigation back
stack.
 Content Providers that enable apps to access data
from other apps, such as the Contacts app, or to
share their own data.
Native C/C++ Libraries
 The Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with
Android.
 It provides platform libraries you can use to manage native activities and access physical
device components, such as sensors and touch input.
 The NDK may not be appropriate for most novice Android programmers who need to use only
Java code and framework APIs to develop their apps.
 However, the NDK can be useful for cases in which you need to do
 squeeze extra performance out of a device when run games or physics simulations.
 Reuse your own or other developers' C or C++ libraries.

 Using Android Studio 2.2 and


higher, you can use the NDK to
compile C and C++ code into a
native library and package it into
your APK using Gradle
Android Run Time (ART)
 Android runtime (ART) is the managed runtime used by applications and some system
services.
 ART and its predecessor Dalvik were originally created specifically for the Android project.
 Google is claiming up to 200% performance improvements overall for ART.
 ART improves garbage collection.
Hardware Abstraction Layer (HAL)
 HAL is responsible for accessing the driver execution hardware.
 A HAL defines a standard interface for hardware vendors to implement, which enables Android
to be agnostic about lower-level driver implementations.
 It allows you to implement functionality without affecting or modifying the higher level system.
Linux Kernel
 A kernel is the core part of any operating system.
 Android OS is built on top of the Linux kernel, with some architectural changes made by
Google.
 Most importantly, Linux is a portable platform that can be compiled easily on different
hardware.
 The kernel acts as an abstraction layer between the software and hardware present on the
 device.
Ex: Consider the case of a camera click. What
happens when you take a photo using the camera
button on your device? At some point, the
hardware instruction (pressing a button) has to
be converted to a software instruction (to take a
picture and store it in the gallery). The kernel
contains drivers to facilitate this process.
Android Platforms
 The Android platform is a platform for mobile devices that uses a modified Linux kernel.
 The Android Platform was introduced by the Open Handset Alliance in November of 2007.
 Most applications that run on the Android platform are written in the Java programming
language.
 To create an application for the platform, a developer requires the Android SDK, which includes
tools and APIs.
 To shorten development time, Android developers typically integrate the SDK.
Android Platforms Contd.

Name Version Number Release Date API Level


Cupcake 1.5 April 27, 2009 3
Donut 1.6 September 15, 2009 4
Hardly anyone use
Eclair 2.0 – 2.1 October 26, 2009 5–7
Froyo 2.2 – 2.2.3 May 20, 2010 8
these versions.
Gingerbread 2.3 – 2.3.7 December 6, 2010 9 – 10
Honeycomb 3.0 – 3.2.6 February 22, 2011 11 – 13
Ice Cream Sandwich 4.0 – 4.0.4 October 18, 2011 14 – 15
Jelly Bean 4.1 – 4.3.1 July 9, 2012 16 – 18
KitKat 4.4 – 4.4.4 October 31, 2013 19 – 20
Lollipop 5.0 – 5.1.1 November 12, 2014 21 – 22
Marshmallow 6.0 – 6.0.1 October 5, 2015 23
Nougat 7.0 – 7.1.2 August 22, 2016 24 – 25 Most devices use
Oreo 8.0 – 8.1 August 21, 2017 26 – 27 one of these APIs.
Pie 9 August 6, 2018 28
Android 10 10 September 3, 2019 29
Setup Android Enviroment
 you can start your Android application development on either
 Mac OS X 10.5.8 or later version with Intel chip.
 Microsoft Windows XP or later version.
 Linux including GNU C Library 2.7 or later.
 Java JDK5 or later version
 You can download the latest version of Java JDK from Oracle's Java site Java SE Downloads.
 You will find instructions for installing JDK in downloaded files, follow the given instructions to install and
configure the setup.
 Finally set PATH and JAVA_HOME environment variable to refer to the directory that contains java and javac.
 Android Studio
 You can download the latest version of Android Studio from Developer’s site.
Building Blocks
 The building blocks are components that you use as an developer to build Android apps.
 Main building blocks of android are
 Activities
▪ An activity is usually a single screen that the user sees on the device at one time.
 Intents
▪ Intents are messages that are sent among the major building blocks.
 Services
▪ Services run in the background and don’t have any user interface components.
▪ Eg file download
 Content Providers
▪ Content providers are interfaces for sharing data between applications.
 Broadcast Receivers
▪ Broadcast receivers are Android’s implementation of a system-wide publish/subscribe mechanism, or more precisely,
an Observer pattern. Eg phone call.
 Application Context
▪ So far you have seen activities, services, content providers, and broadcast receivers. Together, they make up an
application. Another way of saying this is that they live inside the same application context.
Activities
 An application typically has multiple activities, and the user flips back and forth among them.
 As such, activities are the most visible part of your application.
 Just like a website consists of multiple pages, so does an Android application consist of
multiple activities.
 As a website has a “home page,” an Android app has a “main” activity, usually the one that is
shown first when you launch the application.
 And just like a website has to provide some sort of navigation among various pages, an
Android app should do the same.
 We can jump from an activity of one application to another activity in a completely separate
application.
 For example, if you are in your Contacts app and you choose to text a friend, you’d be launching the activity
to compose a text message in the Messaging application.
Activity Life Cycle

• Xml file se sab ui ,etc create ho jata hai


oncreate() method se.

• User ko visible hona start hoti hai onstart()


method se.

• User app se interact kerpata hai


onresume() se.

• When we switch to another app then it is


onpause(). Agar memory khatam hogaye
tho app kill hojati hai and nahi ho tho
onpause se ham onresume() mai aajate
hai.

• Kafi der tak app agar vo onpause() mai


rahe tho vo onstop ho jati hai. Then if
memory ya resources ki kami hogi tho
system usse kill ker dega. Agar resources
ki kami nahi bhi hue then vo onrestart hogi.
E.g. youtube
Activity Life Cycle Contd.
 onCreate()
 It is called when the activity is first created.
 This is where all the static work is done like creating views, binding data to lists, etc.
 This method also provides a Bundle containing its previous frozen state, if there was one.

 onStart()
 It is invoked when the activity is visible to the user.
 It is followed by onResume() if the activity is invoked from the background.
 It is also invoked after onCreate() when the activity is first started.

 onRestart()
 It is invoked after the activity has been stopped and prior to its starting stage.
 Thus is always followed by onStart() when any activity is revived from background to on-screen.
Activity Life Cycle Contd.
 onResume()
 It is invoked when the activity starts interacting with the user.
 At this point, the activity is at the top of the activity stack, with a user interacting with it.
 Always followed by onPause() when the activity goes into the background or is closed by the user.

 onPause()
 It is invoked when an activity is going into the background but has not yet been killed.
 It is a counterpart to onResume().
 When an activity is launched in front of another activity, this callback will be invoked on the top activity
(currently on screen).
 The activity, under the active activity, will not be created until the active activity’s onPause() returns, so it is
recommended that heavy processing should not be done in this part.

 onStop()
 It is invoked when the activity is not visible to the user.
 It is followed by onRestart() when the activity is revoked from the background, followed by onDestroy().
Activity Life Cycle Contd.
 onDestroy()
 onDestroy() is called before the activity is destroyed.
 The activity is finishing due to the user completely dismissing the activity or due to finish() being called on
the activity.
 The system is temporarily destroying the activity due to a configuration change ex. device rotation or multi-
window mode.
Intents
 An intent is to perform an action on the screen.
 It is mostly used to start activity, send broadcast receiver, start services and send message
between two activities.
 It is a messaging object which tells what kind of action to be performed.
 The intent’s most significant use is the launching of the activity.
 Body of Intent:
 action: The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
 data: The data to operate on, such as a person record in the contacts database, expressed as a Uri
 Basically two intents are there in android.
 Implicit Intents
 Explicit Intents
Implicit Intent
 Implicit Intent doesn’t specify the component.
 In such a case, intent provides information on available components provided by the system
that is to be invoked.
 Implicit intents are used without a class name, where Android will help determine an
appropriate Activity to handle the intent.
 For example, you may write the following code to view the webpage.

Intent intent=new Intent(Intent.ACTION_VIEW);


intent.setData(Uri.parse(“http://www.javatpoint.com”));
startActivity(intent);
Explicit Intent
 Explicit Intent specifies the component.
 In such a case, intent provides the external class to be invoked.
 Explicit Intent are used with class name, where Android navigate via routes.

Intent i = new Intent(getApplicationContext(), ActivityTwo.class);


startActivity(i);
Fragment
 A Fragment represents a reusable portion of app's UI.
 A fragment defines and manages its own layout, has its own lifecycle, and can handle its own
input events.
 Fragments cannot live on their
own they must be hosted by
an activity or another
fragment.
 Android Fragment is the part
of activity, it is also known as
sub-activity.
 There can be more than one
fragment in an activity.
 Using with fragment
transaction. we can move one
fragment to another fragment.
Fragment
 Fragment mai bhi hame xml aur java file milti hai just like activity. But hame tool bar , status
bar, etc by default hame nahi milti. Hame yeh sab khud se manage kerna padta hai.
 Fragment mai ham koi bhi chota sa feature banake rakh lete hai like chatting, etc.
 Fragments hame vaha use aate hai jaha hame ek particular feature chahiye but use alag alag
jagah use kerna hai.
Fragment Life Cycle
Fragment Life Cycle
 onAttach():
 The fragment instance is associated with an activity instance.
 The fragment and the activity is not fully initialized.
 Typically you get in this method a reference to the activity which uses the fragment for further initialization
work.
 onCreate():
 The system calls this method when creating the fragment.
 You should initialize essential components of the fragment that you want to retain when the fragment is
paused or stopped, then resumed.
 onCreateView() :
 The system calls this callback when it's time for the fragment to draw its user interface for the first time.
 To draw a UI for your fragment, you must return a View component from this method that is the root of your
fragment's layout.
 You can return null if the fragment does not provide a UI.
Fragment Life Cycle
 onActivityCreated():
 The onActivityCreated() is called after the onCreateView() method when the host activity is created.
 Activity and fragment instance have been created as well as the view hierarchy of the activity.

 onStart():
 The onStart() method is called once the fragment gets visible.

 onResume():
 Fragment becomes active.

 onPause():
 The system calls this method as the first indication that the user is leaving the fragment.
 This is usually where you should commit any changes that should be persisted beyond the current user
session.
Fragment Life Cycle
 onStop():
 Fragment going to be stopped by calling onStop().

 onDestroyView():
 Fragment view will destroy after call this method.

 onDestroy():
 onDestroy() called to do final clean up of the fragment's state but Not guaranteed to be called by the Android
platform.
Mobile Application Development (MAD)
GTU # 3170726

Thank You

You might also like