0% found this document useful (0 votes)
9 views75 pages

Android

Android is an open-source, Linux-based operating system developed by Google for mobile devices, providing a unified approach to application development. The Open Handset Alliance, formed in 2007, supports the Android platform, which has evolved through various versions since its inception in 2003. Key features of Android include process, device, and memory management, along with a rich application framework that simplifies component reuse.

Uploaded by

Asheeqa Kp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views75 pages

Android

Android is an open-source, Linux-based operating system developed by Google for mobile devices, providing a unified approach to application development. The Open Handset Alliance, formed in 2007, supports the Android platform, which has evolved through various versions since its inception in 2003. Key features of Android include process, device, and memory management, along with a rich application framework that simplifies component reuse.

Uploaded by

Asheeqa Kp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 75

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

"Every Cupcake Donates Ecxtra Flavors, Giving Hope,


Ice Jelly Kittens Lick Marshmallows Near Our Pies."
Android 1.0, 1.1

• Did not support soft keyboards.


Android 1.5 (Cupcake) Important

 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

 Google Maps Navigation


 Eclair allowed users to add and sync multiple accounts on a single device.
 Eclair introduced live wallpapers, allowing users to set animated and interactive
backgrounds on their home screens, a unique and visually engaging feature at the time.
 The browser received a major update, including HTML5 support, improved
performance, and double-tap-to-zoom functionality.
 Quick Contact Bar
 Eclair added new camera capabilities, such as digital zoom, scene modes, white
balance, color effects, and macro focus.
 This made the camera more versatile and allowed users to take higher-quality photos.
 Bluetooth 2.1 Support
 Text-to-Speech Enhancements
Android 2.2 (Froyo) 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

• Roboto font family installed


• Hold down the power and volume down buttons to capture a screenshot of the currently running
application.
• Based on an NFC (near field communication) technology called NDEF Push, two Android phones in
close proximity (about 4cm) can securely exchange contacts, web pages, videos, or any other application
defined information you can imagine.
• HD screen , Unlock screen in different ways
Important

Android 4.1 (Jelly Bean)


• Smooth user interface

• Bidirectional text and other language support

Multichannel audio

• Multiple user accounts (tablet only)

• Dial pad auto complete


Android 4.4 (KitKat) Important

• Restrict for apps when accessing external storage


• Wireless printing
• OK Google Voice Commands: Enabled hands-free voice commands with "OK
Google," allowing users to search and perform tasks without touching their devices,
enhancing accessibility and convenience.
• Wireless Display Support: Improved support for wireless display technologies like
Miracast allowed users to stream content to TVs and other displays wirelessly.
• Bluetooth Low Energy (BLE) Support
• Support for NFC Payments (Tap & Pay)
• Immersive Mode : This mode allowed apps to use the entire screen by hiding the
status and navigation bars, enhancing the user experience for games and media
consumption.
• Provided full-color emoji support in the system, improving the way users expressed
emotions and ideas in messages.
Important
Android 5.0 (Lollipop)

• 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

• Password auto fill

• Snooze notification(you slid the notification card to the left or right


and tapped )

• Notification dots

• New Emoji Styling

• Smart Text Selection

• Auto Enable WiFi


Android 9.0 Pie

 Tap into Gestures

 Smarter Battery

 Adaptive Brightness

 Improve Notification

 App Actions(App Actions let users launch and control Android apps with

their voice, using Assistant.)


Android software
stack/
Android
architecture

diagram
Linux kernel  Core services (including hardware drivers , process

and memory management, security, network and

power management) are handled by Linux 2.6 kernel.

 The kernel also provides an abstraction layer between

the hardware and the remainder of the stack.

 Eg: display ,camera ,wifi (drivers).


Libraries

• Running on the top of the kernel.

• Run in system background.

• Media library for playback audio and video media

• A surface manager to provide display management(2D and 3D graphic layer)

• Graphics libraries that include SGL and OpenGL for 2D and 3D graphics

• SQLite for native database support(light weight RDBMS )

• SSL for internet security

• Webkit for Browse engine.

• FreeType: bitmap and vector font rendering


Android Runtime

1. Core libraries

(Provides the functionalities of the java programming)

2. Dalvik virtual machine


Dalvik Virtual Machine
 It is an android virtual machine optimized for mobile devices. It optimizes the virtual
machine for memory, battery life and performance.
 Dalvik bytecode
 Combines java class files
 Android SDK can transform compiled java class into .dex format

• Register based

• Execute files in the dalvik executable format(.dex)

• Multiple DVM can run at the same time.

• Multiple class files are converted into one dex file

The Android Assets Packaging Tool (aapt) handles the packaging


process.
DVM (Dalvik Virtual Machine) JVM (Java Virtual Machine)

1 It is Register based which is designed to run on It is Stack based.


low memory.

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.

7 Here the executable is APK. Here the executable is JAR.


Application Framework
 Simplify the reuse of components
 It provides the classes used to create android applications

The Android framework includes the following key services −


 Activity Manager − Controls all aspects of the application lifecycle and activity stack.
 Content Providers − Allows applications to publish and share data with other
applications.
 Resource Manager − Provides access to non-code embedded resources such as strings,
color settings and user interface layouts.
 Notifications Manager − Allows applications to display alerts and notifications to the
user.
 View System − An extensible set of views used to create application user interfaces.
 This is the layer that end-users interact with.
 It is on this layer where application developers publish
their applications to run
Application  It provide a set of core libraries:
 Home
 Contacts
 Messages
 Email
 Browser
 Notification Drawer
1. Activities
2. Services
3. Broadcast Receivers
Application components/ 4. Content Providers
Fundamental components 5. Additional Components
1. Fragments
2. Views
3. Layouts
4. Intents
5. Resources
6. Manifest
Activity
 An activity is the entry point for interacting with the user.

 It represents a single screen with a user interface.

 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.

 It doesn't has any UI (user interface).

 The service runs in the background indefinitely even if application


is destroyed.

 They can be connected to other components and do inter-process


communication (IPC).
Broadcast Receivers
BATTERY Charger
connecte WiFi avalability
LOW
d/discon
nected

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.

 Content provider will help for inter process communication.

 A content provider can use different ways to store its data and the data can be stored in

a database, in files, or even over a network.

 e.g., whatsapp and

 contact communication
Fragments
• Android Fragment is the part of activity, it is also known as sub-

activity.

• There can be more than one fragment in an activity.

• Fragments represent multiple screen inside one activity.


Views
• A view is an object that draws something on the screen that the user can interact with.

• 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.

• Common layouts are:


1. Linear layout
2. Relative layout
3. Frame layout
4. Table layout
Intents
• To communicate with one activity from another activity we use component called intent.

• Intent is a messaging object used to request an action from app component

Intent for broadcast messaging


Resources
 A resource in android is a file or a value that is bound to an executable

application in such a way that you can change them or provide alternatives

without recompiling the application.

 Examples of resources include strings, colors, bitmaps and layouts.

 Android support externalisation of resources.

 These resources are always maintained separately in various sub-directories

under res/ directory of the project.


• Configuration file for the application.
Manifest
• The manifest lets you define the structure and metadata of your

application and its components.

• 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

real device capabilities.

 It works with the emulator to provide a virtual device specific environment in which to install

and run android applications.

 In computing , an emulator is hardware or software that enables one computer system(host)

to behave like another computing system(guest)

 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.

7. Emulation of Hardware Features: Android emulators can simulate various hardware


functionalities like GPS, accelerometers, cameras, and fingerprint scanners. This allows
developers to test how their apps will respond to different hardware interactions.

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

3.res (Resources) 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.

• Components: Describes the various components of the application, such as activities,

services, content providers, and broadcast receivers.

• Minimum and target SDK versions: Specifies the minimum and target versions of the

Android SDK that the application supports.

• Hardware and software requirements: Specifies any specific hardware or software

requirements for the application to function properly.

• 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

like images, XML layouts, UI strings for our android application.

• 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

Storing Media Files:


• The res/raw folder is perfect for storing media files like audio files (MP3,
WAV), video files, or other types of binary data (like PDFs).
• These files are bundled with your APK, so they are available to your app at
runtime.
Resource IDs:
• Unlike files in the assets folder, files in the res/raw folder are assigned
resource IDs automatically by the Android system. This means you can
access them using the R.raw class.
ANDROID SDK MANAGER

• SDK stands for Software Development Kit, which is a collection of


software tools required.
• SDK basically helps Android to download tools and recent versions of
Android.
• Every time a new Android version is released, along with it is released an
SDK corresponding to it.
• This SDK must be installed by the developers for the devices.
What is a build tool?
• A build tool is nothing, but a set of programs that are used to automate
the creation of executable applications from their source codes. Here
creating the executable applications includes the task of compiling,
testing, deploying, linking, and packing the codes into a usable form.

• It's installed in the <sdk>/build-tools/ directory.

What is the role of Gradle in Android?


See you know that every single android application development tool needs to compile
resources, source codes, libraries and then combine them to an APK. Right?
So, Android needs a build system to do these tasks and run the app. That is where the
Android gradle.build system comes into play. It is the responsibility of the Gradle to
perform the task of compilation, testing, deployment, and conversion of the code into
a .dex file.
How Android Gradle works?

So the answer to this is that the Android System supports


Gradle as it builds automation tools out of the box. The build
system of Android compiles the resources, the java source
code and then packs them into an Application Package. This
package can be tested, deployed, signed, and distributed by
you.
Gradle
 Gradle is a build automation system that is used to automate the building, testing, and deployment of
software. It is a popular choice for Android development, and is used by Android Studio to automate
the build process.

 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

1. Protecting User Privacy


• Permissions control what your app can access on a user’s device (e.g., location, camera, contacts,
microphone, etc.).
• Without proper permissions, apps could potentially misuse sensitive data, leading to privacy breaches.
• Users are more likely to trust your app if it transparently requests only the permissions it truly needs.
2. Ensuring Security
• Permissions help protect the system and user data from malicious or poorly coded apps. For example,
an app cannot access the internet, send SMS, or read files on the device unless explicitly granted
permission.
• By using permissions correctly, you can prevent your app from being exploited by attackers who may
attempt to access sensitive resources on the device.
3. Maintaining Functionality
• Apps need permissions to access specific device features. For example, a navigation app needs location
permissions, and a camera app needs access to the device's camera and storage.
• If your app doesn’t request the correct permissions, it may not work as intended, leading to poor user
experience and bad reviews.
• need to access the user’s contacts or send/receive text messages.
4. User Control and Transparency
• Modern Android versions (Android 6.0 and above) use a runtime permission model, where users grant
or deny permissions at runtime rather than during installation.
• This gives users control over what data they are comfortable sharing, promoting transparency and
enhancing user trust.
• Your app should handle permission requests gracefully, explaining why specific permissions are
needed, so users can make informed decisions.
5. Compliance with Regulations
• In some regions, data privacy regulations like GDPR (General Data Protection Regulation) and CCPA
(California Consumer Privacy Act) require that apps request permission to access personal data.
• Ensuring proper permission handling can help your app remain compliant with these laws, reducing
the risk of legal penalties.
6. Optimizing Battery and Performance
• Permissions can also indirectly impact battery life and device performance. For example, accessing
GPS data frequently can drain battery life quickly.
• By requesting only the necessary permissions, you can optimize your app’s efficiency and avoid
draining resources unnecessarily.
Examples of Permissions
• Location Access: Required for apps that use maps, geolocation, or location-based services.
• Camera and Microphone: Needed for apps that capture photos, videos, or audio.
• Storage: Required for apps that read or write to the device’s internal or external storage.
• Contacts and SMS: Useful for apps that
Application life cycle
Activity life cycle(same)

 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.

 The method is executed only once during the life time.

 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,

the value of the Bundle object is null.

 setContentView(Layout) sets the layout for your activity.

 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.

 super is used to call the parent class constructor


@Override
public void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.YOUR_XML_LALYOUT);
}
3. onResume():
2. onStart():  Similar to previous methods this method is invoked when
activity enters in the resumed state. Typically This is
 Whenever your activity is in the started state, the called when the user starts interacting with the
system calls this method. application.

  Typically, the onResume() callback restarts any paused UI


This is a state where activity gets visible to the user
updates, threads, or processes required by the activity but
and the user can now interact with the application. suspended when it was inactive
 Our application does not stay in this callback method  At this point, the activity is at the top of the activity stack,
for long. with a user interacting with it. Always followed by
 onPause() when the activity goes into the background or
In this method, we can perform any operation related is closed by the user.
to the UI components
 This is a good place to begin animations, open exclusive-
 access devices (such as the camera), etc.
protected void onStart()
 Our app is in this state until something interrupts our
{
application like while using app user receives a phone
Toast toast = call.
Toast.makeText(getApplicationContext(),"onStart
 protected void onResume(){ Toast toast =
Called",Toast.LENGTH_LONG).show();}
Toast.makeText(getApplicationContext(),"onResume
Called",Toast.LENGTH_LONG).show();
}
4. onPause(): 5. onStop():
 This method is invoked when the activity is  This method is invoked when your app enters
running in the background but not killed in a stopped state.
completely yet. Typically it is counter to  The stopped state is when your activity is no
onResume(). longer visible to the user,.
 You can use this method to release system  protected void onStop(){ Toast toast =
resources used in this activity that may affect Toast.makeText(getApplicationContext(),"onS
the device battery life. top Called",Toast.LENGTH_LONG).show();
}
 In the onPause() method, we may commit
database or perform light weight processing
before the activity goes to the background.
 protected void onPause(){ Toast toast =
Toast.makeText(getApplicationContext(),"o
nPause
Called",Toast.LENGTH_LONG).show();
}
6. onDestroy(): 7. onRestart():
 The final call received before the activity  It is invoked after the activity has been
is destroyed. This can happen stopped and prior to its starting stage.
 protected void onRestart(){ Toast toast =
1. because the activity is finishing
Toast.makeText(getApplicationContext(),"
(when finish() is invoked) or onRestart
2. because the system is temporarily Called",Toast.LENGTH_LONG).show();}
destroying this instance of the activity to
save space.
protected void onDestroy(){ Toast toast =
Toast.makeText(getApplicationContext(),"on
Destroy
Called",Toast.LENGTH_LONG).show();
}
 When the activity comes back to focus from the paused state, onResume() is invoked
 When we reopen any app(after pressing Home Key),activity now transit from stopped state
to the active state.
 Thus onStart() and onResume() methods are invoked.
 To destroy the activity on the screen, we can hit the back key, this moves the activity into
the destroyed state.
 During this event, onPause(), onStop(), and onDestroy() methods are invoked.
 Whenever we change the orientation of the screen i.e. from portrait to landscape or vice-
versa , life cycle methods starts from the start i.e. from onCreate() method
 This is because the complete spacing and other visual appearance gets changed and
adjusted.
Android java packages
 In Android development using Java, various packages are used to organize and
structure code. These packages contain classes and interfaces that provide the
necessary functionality for developing Android applications

• android.app: This package contains the fundamental components of an

Android application, such as activities, services, content providers, and

broadcast receivers.

• android.content: This package provides classes for accessing and

publishing data between applications. It includes content providers that

manage access to a structured set of data, as well as classes for


• android.os: This package provides classes that allow you to work with the operating system,
such as managing application resources, creating and managing threads, and communicating
with other applications.
• android.view: This package contains classes that define the basic building blocks for user
interface components, such as views, layouts, and widgets.
• android.widget: This package provides a set of UI elements that can be used to build the user
interface of an Android application, including buttons, text fields, lists, and more.
• android.database: This package provides classes for managing data in a SQLite database. It includes classes for
creating and managing database content providers and SQLite databases.
• android.net: The android.net package offers classes for working with network-related functionalities, such as accessing
the internet, making network requests, and managing network connectivity.
• android.webkit: This package provides classes for integrating web content into your application, allowing you to
display web pages within your app.
 android.graphics: This package provides classes for 2D graphics and drawing. It includes classes for shapes, colors,
images, and text rendering.
 android.media: This package contains classes for controlling various media aspects, such as audio and video
playback.
The development of end user application using Android SDK.
1.Set Up the Development Environment: Install Android Studio, the official integrated development environment (IDE)
for Android development. Ensure the Android SDK is installed along with necessary tools like emulators and build
configurations.
2.Create a New Project: Use Android Studio to create a new project. Choose a project template (e.g., Empty Activity)
that suits the application's requirements.
3.Design the User Interface (UI): Use XML to define the application's UI elements. Android Studio's layout editor
allows developers to drag and drop components like buttons, text fields, and images.
4.Write Application Logic: Use Java to define the application's behavior. The activity class handles user interactions
and links UI elements to backend logic.
5.Add Features Using APIs: Integrate Android SDK APIs for features like location services, camera access, database
management (Room or SQLite), and more.
6.Test the Application: Use emulators or physical devices to test the application. Debugging tools in Android Studio help
identify and resolve issues.
7.Build and Sign the APK: Generate a signed APK (Android Package) or App Bundle for release. This step involves
configuring build settings and signing the app with a developer key.
8.Publish the Application: Upload the APK to the Google Play Store or distribute it through other means. Follow
Google's guidelines for app submission, including metadata and screenshots.

You might also like