Android
Android
PROGRAMMING
Leeshma K
Assistant Professor
Department of Computer Science
It is an open source operating system
Middleware
Key application
Created by google and OHA
Android Linux based (2.6 kernel) operating system.
Process management
Device management
Memory management
It is based on java
• Android is a software package and an open source Linux based operating system for
mobile devices such as smart phones and tablets.
• Android offers unified approach to application development for mobile devices .
• Developers need only develop for android , and their applications should be able to run
on different devices powered by android.
Open Handset Alliance (OHA)
The Open Handset Alliance (OHA) is a consortium of 84 firms to develop open
standards for mobile devices.
The OHA was established on 5 November 2007, led by Google with 34 members,
including mobile handset makers, application developers , some mobile network
operators and chip makers.
The OHA's main product is the Android platform - the world's most popular
smartphone platform.
October 2003 –android was originally created by Andy Rubin,Rich Miner, Nick Sears, and Chris White .
July 2005 –google acquired Android Inc. and made Andy Rubin, the director of mobile platforms for Goog
November 2007-Open Handset Alliance was formed and Android was launched.- Android alpha released
September 2008-Android 1.0. released.(T mobile G1 ,first android based smart phone)
October 2008-Android was open sourced.
Version history
• Android 1.0 • Android 6.0 Marshmallow
• Android 1.1 • Android 7.0 Nougat
• Android 1.5 Cupcake • Android 8.0 Oreo
• Android 1.6 Donut • Android 9 Pie
• Android 2.0 Éclair • Android 10 Android Q
• Android 2.2 Froyo • Android 11 Red Velvet
• Android 2.3 Gingerbread Cake
• Android 3.0 Honeycomb • Android 12 Snow Cone
• Android 4.0 Ice Cream Sandwich • Android 13 Tiramisu
• Android 4.1 Jelly Bean • Android 14
• Android 4.4 KitKat
• Android 5.0 Lollipop
Version Key Features
Android 1.0, 1.1 No soft keyboard, Basic apps (Gmail, Maps), Early web browsing, Android Market, Basic camera
Android 1.5 (Cupcake) Virtual keyboard, Home screen widgets, Video recording, YouTube/Picasa upload, Auto-rotation
Android 1.6 (Donut) Quick Search Box, Multi-screen support, Battery Indicator, App Market updates, TTS
Android 2.0 (Éclair) Multi-account sync, Live wallpapers, HTML5 browser, Camera enhancements, Quick Contact Bar
Android 2.2 (Froyo) JIT Compiler, Wi-Fi Hotspot, Push notifications (C2DM), Voice commands, Flash support
Android 2.3 (Gingerbread) NFC support, VoIP calls, Improved keyboard, Game development tools, Download manager
Android 3.0 (Honeycomb) Tablet UI, Action bar, Fragments, Dual-core processors, Google Talk video chat
Android 4.0 (Ice Cream Sandwich) Unified UI, Face unlock, NFC Beam, Screenshot capture, Roboto font
Smooth UI (Project Butter), Google Now, Multi-user accounts (tablet), Wireless display, Expandable
Android 4.1 to 4.3 (Jelly Bean)
notifications
Android 4.4 (KitKat) Low-end optimization, Immersive Mode, Wearable support, "OK Google" voice search, Emoji updates
Android 5.0 (Lollipop) Material Design, Lock-screen notifications, Project Volta (battery), ART runtime, Guest mode
Android 6.0 (Marshmallow) Doze mode (battery), Fingerprint support, Runtime permissions, USB Type-C, Google Now on Tap
Android 7.0 (Nougat) Multi-window, Vulkan API (graphics), Seamless updates, Data Saver, Notification grouping
Android 8.0 (Oreo) Picture-in-Picture, Notification Dots, Autofill forms, Background app limits, Adaptive Icons
Android 9.0 (Pie) Gesture navigation, Adaptive Battery, Smart notifications, Digital Wellbeing, App Slice actions
Cupcake was the first version of Android to feature an on-screen, virtual keyboard,
making it possible to use Android on devices without a physical keyboard.
Cupcake introduced support for home screen widgets, allowing users to place
interactive elements, like clocks, weather updates, and music players, directly on their
home screen.
The camera app included options for both image capture and video recording,
broadening the multimedia capabilities of Android.
Cupcake included the first instance of a copy-and-paste feature in the web browser,
improving browsing and productivity.
Auto-Rotation
Bluetooth Support
Users could upload videos directly to YouTube and photos to Picasa, integrating
Android with Google’s other services and making sharing content easier.
Important
Android 1.6 (Donut)
• Donut introduced a Quick Search Box that allowed users to search for
content across the phone (contacts, web, apps, etc.) from a single search
box on the home screen. This feature made finding information more
efficient.
• Donut was the first version to support different screen sizes and
resolutions, enabling Android to be used on a wider variety of devices.
• Battery Usage Indicator
• The Android Market (now Google Play Store) was updated with features like
app screenshots, descriptions, and reviews, making it easier for users to
discover new apps.
• Text-to-Speech (TTS) Functionality.
• Camera and Gallery Improvements:
• CDMA Support:
• Updated Virtual Keyboard:
• The on-screen keyboard was refined to make typing faster and more
accurate, including better support for voice input.
2.0 (Eclair) Important
•Froyo introduced the Dalvik Just-In-Time (JIT) Compiler, which significantly improved the speed and
responsiveness of applications by optimizing how code was processed.
•Wi-Fi Hotspot
•Froyo brought C2DM (Cloud to Device Messaging), which enabled developers to send notifications to
devices even when apps were not running, laying the groundwork for today’s push notification services.
•USB Tethering
•Android 2.2 added Voice Actions, allowing users to perform tasks like calling, texting, and searching
the web by simply speaking commands.
•This was an early step toward voice-controlled interactions on Android devices, which would later
evolve into Google Assistant.
•The browser in Froyo was updated to support Adobe Flash 10.1, enabling users to access Flash-
based websites and games.
•App Storage on SD Card
•Automatic App Updates
•PIN Lock and Enhanced Security
Android 2.3 (Gingerbread)
• VoIP calls.
• A new on-screen keyboard with improved predictive text input and
a better layout for faster typing.
• Introduced the ability to copy and paste text across different apps,
a feature that improved text manipulation.
• Enhanced tools for game developers, including support for game
controllers and improved 3D graphics.
• Initial support for Near Field Communication (NFC), paving the
way for contactless payments and other uses.
• A new download manager that allowed users to see ongoing
downloads and notifications for completed downloads.
Important
Android 3.0 (Honeycomb)
• Developed particularly for large screen sized devices
(Android for tablets)
• Dual core Processor
• Use large screen
• Action bar, drag and drop
• Voice and video chat with Google Talk friends
• Google Books.
• Fragments introduced(entire screen can be divided into
multiple segments and each segment can perform
different function)
Android 4.0 (Ice Cream Sandwich)
• Unified API for Tablets and Phones. Android 3 was just for tablets, so most developers took a pass on
it. Android 4 is for both phones and tablets.
• Camera, face detection, auto focus, Video, photo, live effects Important
Multichannel audio
• Material Design: A new design language that emphasized flat elements, vibrant colors, and
animations, providing a more modern and cohesive look across the operating system and apps.
• Notifications on the Lock Screen: Introduced actionable notifications on the lock screen,
allowing users to view and respond to notifications without unlocking their devices.
• Introduced Smart Lock, which allowed users to keep their devices unlocked in certain trusted
environments, such as when connected to a trusted Bluetooth device or in specific locations.
• New Quick Settings Menu allowed users to access frequently used settings and toggle features
like Wi-Fi and Bluetooth more easily.
• Introduced a guest mode that allowed users to share their device without giving access to
personal information.
• Launched Google Fit, an integrated health and fitness platform that allowed users to track their
fitness activities and health metrics.
• Introduced Project Volta, aimed at improving battery life and providing tools for developers to
create more efficient apps.
• Replaced the Dalvik runtime with the ART (Android Runtime), improving app performance and
memory usage.
Android 6.0 (Marshmallow)
• Introduce Doze mode to reduce CPU speed when screen is off mode(In Doze
mode, the system attempts to conserve battery by restricting apps' access to
network and CPU-intensive services. It also prevents apps from accessing the
network and defers their jobs, syncs, and standard alarms.)
• Finger print reader support , 4K display mode for apps (4K resolution refers to
a horizontal display resolution of approximately 4,000 pixels.)
• MIDI supports (Musical Instrument Digital Interface) is a standard protocol for
interconnecting computers with musical instruments, stage lighting, and other
time-oriented media.)
• USB Type- C supports
Android 7.0 Nougat
• To use two or more languages at the same time.
• Can switch between apps and run two apps side by side.
• Game changer with high performance 3D graphics with sharper graphics and eye
candy effects
• Visual reality mode –Daydream-ready phones
• Seamless Updates
• Direct Boot
• Data Saver
• Notification control
• File based encryption
Android 8.0 Oreo
• Picture in picture
• Notification dots
Smarter Battery
Adaptive Brightness
Improve Notification
App Actions(App Actions let users launch and control Android apps with
diagram
Linux kernel Core services (including hardware drivers , process
• Graphics libraries that include SGL and OpenGL for 2D and 3D graphics
1. Core libraries
• Register based
2 DVM uses its own byte code and runs the JVM uses java byte code and runs “.class” file
“.Dex” file. From Android 2.2 SDK Dalvik has having JIT (Just In Time).
got a Just in Time compiler
3 DVM has been designed so that a device can run A single instance of JVM is shared with multiple
multiple instances of the VM efficiently. applications.
Applications are given their own instance.
4 DVM supports the Android operating system JVM supports multiple operating systems.
only.
5 For DVM very few Re-tools are available For JVM many Re-tools are available.
6 There is a constant pool for every application. It has a constant pool for every class.
One app might have one activity and more than one activity.
The invisible workers of your application.
Services
Android service is a component that is used to perform operations
on the background such as playing music, handle network
transactions, interacting content providers etc.
Bluetooth device
Incomig SMS Incoming call
connected Should create
and register
They handle communication between Android OS and applications. broadcast
receiver into
Perform an action in response to a message from some other component. your
application.
Broadcast Receiver simply respond to broadcast messages from other
It is simply a
applications or from the system itself. These messages are called events. listener to the
system
generated or
other events
Content provider
A content provider component supplies data from one application to others on request. Such
requests are handled by the methods of the ContentResolver class.
Content providers let you centralize content in one place and have many different applications
access it as needed.
A content provider can use different ways to store its data and the data can be stored in
contact communication
Fragments
• Android Fragment is the part of activity, it is also known as sub-
activity.
• Commonly used
Views are :
• EditText
• ImageView
• TextView
• Button
• ImageButton
• CheckBox
Layouts
It defines the visual structure for a user interface, such as
the UI for an activity or app widget.
All elements in the layout are built using a hierarchy of
view and view group objects.
application in such a way that you can change them or provide alternatives
• AndroidManifest.xml
Android virtual device (AVD)
AVD is a device configuration that is run with the android emulator.
It is an emulator configuration that allows developers to test the application by stimulating the
It works with the emulator to provide a virtual device specific environment in which to install
Emulator enables the host system to run software or use peripheral devices designed for the
guest system.
Importance of Android Emulator
1. Testing and Debugging: An emulator allows developers to test and debug Android applications without the need for
physical devices. It simulates various Android versions, device configurations, screen sizes, and hardware capabilities.
2. Cost-Effective: Emulators eliminate the need to purchase multiple physical devices, especially when testing apps on
different Android versions and screen resolutions.
3. Convenience and Speed: Emulators are faster to set up than physical devices and provide features like instant
installation of apps, snapshots of device states, and easy access to logs and debugging tools.
4. Simulating Real-World Scenarios: Developers can test apps under specific conditions (e.g., low battery, varying
network speeds, different geolocations) to ensure robustness before deployment.
5. Accessibility for Development Teams: Emulators are accessible to developers, regardless of their physical device
availability, making it easier to collaborate and develop apps on various platforms.
6. Quick Iteration: Emulators enable developers to quickly run applications and see changes
without the need to connect, disconnect, or set up physical devices. This rapid feedback loop
helps speed up the development cycle.
8. Cross-Platform Compatibility: Emulators can mimic a wide range of Android devices, making it
easier to ensure that applications function correctly on different versions of the Android OS, from
older versions to the latest releases.
9. Support for Automated Testing: Emulators are often integrated with automated testing
frameworks. This allows developers to run unit tests, UI tests, and integration tests in a
consistent environment, ensuring the stability of the application across updates.
10. Virtual Device Configuration: Developers can configure emulators to simulate specific devices,
down to the hardware specifications, OS version, and network conditions. This flexibility ensures
that apps are tested under varied and controlled conditions.
11. Backward Compatibility: Emulators provide the ability to test applications on older versions of
Android, ensuring that updates to the app do not break functionality for users on older devices.
ANDROID PROJECT FOLDER
STRUCTURE
1.Manifests Folder
2.Java Folder
1. Drawable Folder
2. Layout Folder
3. Values Folder
4. Raw folder
4.Gradle Scripts
AndroidManifest.xml
• The AndroidManifest.xml file is an important part of an Android application.
• It is an XML file that serves as a descriptor of the application, providing essential
information about the app to the Android operating system.
• This file is crucial for the Android system to understand the various components and
requirements of the application.
• Package name: Unique identifier for the application.
• Permissions: Defines the system permissions required by the application to access certain
features or data.
• Minimum and target SDK versions: Specifies the minimum and target versions of the
• Intent filters: Declares the types of intents that an activity, service, or broadcast receiver can
respond to.
Why Do You Need AndroidManifest.xml?
1.App Configuration: It provides a roadmap for the Android system on how to run your
application.
2.Permissions Handling: Ensures that your app has the appropriate permissions before
accessing system resources or sensitive data.
3.Component Declaration: Without declaring activities, services, or broadcast receivers,
they won't function or be recognized by the system.
4.Ensures Compatibility: By specifying minSdkVersion and targetSdkVersion, you
control which devices can run your app, ensuring compatibility with different Android
versions.
5.Entry Point Management: The manifest determines which activity to launch first
when the user taps your app icon.
• Resource folder is the most important folder because it contains all the non-code sources
• Java folder contains all the java source code (.java) files which we
create during the app development, including other Test files.
1. res/drawable folder
• It contains the different type of images used for the development of the
application.
• We need to add all the images in drawable folder for the application
development.
2. res/layout folder
• Layout folder contains all XML layout files which we used to define
the user Interface of our application.
• It contains the activity_main.xml file.
4. res/values folder
• Values folder contains a number of XML files like strings, dimens,
colors and styles definitions.
• One of the most important file is strings.xml file which contains the
resources.
The raw (res/raw) folder is one of the most important folders and it
plays a very important role during the development of android projects
in android studio. The raw folder in Android is used to keep mp3,
mp4, sfb files, etc. The raw folder is created inside
the res folder: main/res/raw. So we will simply create it inside the res
folder.
In Android one can store the raw asset file like JSON, Text, mp3, HTML,
pdf, etc in two possible locations:
1.assets
2.res/raw folder
Assets folder
The assets folder in Android is used to store files that your app needs to access directly, without any
processing by Android. Here’s why it’s useful:
• The assets folder can store any type of file—text files, HTML, JavaScript, images, videos, fonts,
JSON, CSV, etc.These files are stored in their original format and are not compiled into resource IDs
like files in the res folder (e.g., res/raw).
• Flexible Loading: It’s great if you need to load files like web content (HTML pages, JavaScript,
etc.) or use files that don’t fit the regular resource types (like raw databases or templates).
res/raw folder
Gradle uses a domain-specific language (DSL) based on Groovy to define the build process. This DSL
allows you to define the tasks that need to be performed to build your project, as well as the
dependencies between those tasks.
Gradle also provides a rich set of features for managing dependencies. This includes the ability to
declare dependencies on external libraries, as well as the ability to resolve those dependencies
automatically.
Android Studio provides a number of plugins that make it easy to use Gradle to build Android apps.
These plugins provide tasks for compiling code, packaging resources, running tests, and signing and
deploying apps.
Importance of Setting up permissions in app
The phase that an application goes through from start to end is called application life cycle.
Each android application runs inside its own instance of a virtual machine
At any point in time several parallel VM instances could be active
Unlike a common Window or Unix process, an android application does not completely control the
completion of life cycle.
Every android application should be prepared for untimely termination
Occasionally hardware resources may become critically low and the OS could order early termination
of any process.
The decision considers factor such as:
Number and age of the application components currently running
Relative importance of those components to the user
How much free memory is available in the system.
To manage limited system resource the Android system can terminate running
applications
If the android system needs to terminate process it follows the following priority
system.
Foreground
Visible
Service
Background
Empty
All processes in the empty list are added to a least recently used list(LRU)
The processes which are at the beginning of this list will be the ones killed by the
out of memory killer
If an application is restarted by the user, its gets moved to the end of this queue.
States of an activity
1. Active state 2. Paused state
When an activity is in active An activity being in this state means
state, it means it is active that the user can still see the
and running. activity in the background such as
behind the transparent window or a
It is visible to the user and dialog box ie. It is partially visible.
the user is able to interact The user cannot interact with the
with it. activity until he/she is done with the
Process state is foreground current view.
Process state is background.
Android runtime treats the
Android runtime is usually does not
activity in this state with the kill the activity in this state but may
highest priority and never do so in an extreme case of resource
tries to kill it. crunch.
3. Stopped state 4. Destroyed state
When an activity is started When a user hits a Back key
on the top of the current one or Android Runtime decides
or when a user hits the to reclaim the memory
home key, the activity is allocated to an activity i.e.
brought to stopped state. in the paused or stopped
The activity in this state is state, It goes into the
invisible, but it is not Destroyed state.
destroyed The activity is out of the
Process state is background memory and is invisible to
the user.
Android runtime may kill
such an activity in case of
resource crunch.
Life cycle methods
• onCreate(savedInstanceState)
• onStart()
• onRestart()
• onResume()
• onPause()
• onStop()
• onDestroy()
onCreate(savedInstance State)
When your system first creates an activity, onCreate() is the first
function that gets called by the system.
In this method, you perform the basic operations like setting up the
variable or our instances.(initialization of variables).
This method receives a parameter savedInstanceState, which is a Bundle object
containing the activity’s previously saved state. If the activity has never existed before,
If the orientation changes(i.e rotating your device from landscape mode to portrait and
vice versa), the activity is recreated and onCreate() method is called again, so that you
don't lose this prior information. If no data was supplied, savedInstanceState is null.
broadcast receivers.