SlideShare a Scribd company logo
1 of 82
Download to read offline
From A to Z
Android
Hazem Hagrass
Senior Software Engineer
hazem.hagrass@badrit.com 2
Agenda
● Overview
● Architecture
● Environment Setup
● Project Structure and modules
● Application Components
⚪ Intents and Filters
⚪ Activities
⚪ Services
⚪ Broadcast Receivers
3
Overview
4
Android: The Forgotten History
The Forgotten History
● Created by Andy Rubin, a free, open source mobile platform that any coder
could write for and any handset maker could install.
● “There were nearly 700 million cell phones sold each year compared with fewer than 200 million
PCs and the gap was widening. Increasingly, phones were the way people wanted to connect with
each other and with everything else” Andy Rubin.
5
The Forgotten History
● He would make his money by selling support for the system security services,
or email management.
6
The Forgotten History
● Rubin discussed the idea with Larry Page(Google's CEO), he didn’t want
money from Page. He already had funding. What he wanted was Google’s
imprimatur, even an email from Page would do.
● Rubin figured he could attract more VC funds with the search giant on board,
possibly with a hint that Google might be interested in developing its own
branded phone. He pulled out a prototype.
7
The Forgotten History
● When Apple introduced the iPhone in 2007, Google was already working on
Android, its own smartphone operating system. Google bought Android, which
was Rubin's startup, for ~$50 million in 2005.
8
Who is OHA?
9
Who is OHA?
10
● The OHA was established on 6 November 2007
● it is led by Google with 47 members including mobile handset makers,
application developers, some mobile carriers and chip makers.
● Android, the flagship software of the alliance, is based on an open source
license and has competed against mobile platforms from Apple (iOS),
Microsoft, Nokia (Symbian), HP ( Palm), Samsung Electronics / Intel (Tizen,
bada), and Blackberry.
Steve Jobs!
"Everything is a f**king rip off of what we're doing," Jobs said of Android
11
Android powers hundreds of millions of mobile
devices in more than 190 countries around the world.
It's the largest installed base of any mobile platform
and growing fast
Android, the world's most popular mobile platform
12
Market Share
13
● Every day more than 1 million new Android devices are
activated worldwide.
● 1.5 billion downloads a month and growing. Get your
apps in front of millions of users at Google's scale
● Android Nears 80% Market Share In Global Smartphone
Shipments, As iOS And BlackBerry Share Slides, Per IDC
Play Store
14
Android is open!
Android is Open, it is built on the open Linux Kernel.
it can be liberally extended to incorporate new cutting edge technologies as
they emerge. The platform will continue to evolve as the developer
community works together to build innovative mobile applications.
Android was built from the ground-up to enable developers take full
advantage of all a handset has to offer.
It was built to be truly open. For example, an application can call upon any of
the phone’s core functionality such as making calls, sending text messages, or
using the camera
15
All applications are created equal
Android does not differentiate between the phone’s core applications and
third-party applications. They can all be built to have equal access to a
phone’s capabilities providing users with a broad spectrum of applications
and services
Equality
16
Architecture
17
System Architecture
Architecture
18
Linux Kernel
● The Android OS is derived from Linux Kernel 2.6 and is actually created from
Linux source
● This provides basic system functionality like process management, memory
management, device management like camera, keypad, display etc. Also,
the kernel handles all the things that Linux is really good at such as
networking and a vast array of device drivers, which take the pain out of
interfacing to peripheral hardware.
19
Libraries
● This layer holds the Android native libraries written in C/C++ and offer
capabilities similar to the above layer, while sitting on top of the kernel.
● Set of libraries including open-source Web browser engine WebKit, well
known library libc, SQLite database which is a useful repository for storage
and sharing of application data, libraries to play and record audio and video,
SSL libraries responsible for Internet security etc.
20
It provides a key component called Dalvik Virtual Machine which is a kind of Java
Virtual Machine specially designed and optimized for Android. When we say it is
for embedded devices, it means it is low on memory, comparatively slower and
runs on battery power. The Dalvik VM enables every Android application to run
in its own process, with its own instance of the Dalvik virtual machine. The
Android runtime also provides a set of core libraries which enable Android
application developers to write Android applications using standard Java
programming language.
Android Runtime
21
Application Framework
It is the layer which application developers can leverage in developing Android
applications. The framework offers a huge set of APIs used by developers for
various standard purposes, so that they don't have to code every basic task.The
framework consists of certain entities.
22
Your application to be installed on this layer only. Examples of such applications
are Contacts Books, Browser, Games etc.
Applications
23
Environment Setup
24
Installation
Now everything is easy and can be done on one click just by download Android
SDK tools which contains:
● Android Studio IDE
● Android SDK tools
● Android 5.0 (Lollipop) Platform
● Android 5.0 emulator system image with Google APIs
Installation
25
Project Structure
26
Structure and modules
Top Level Folders
27
● Main Project: This would be entire project context (Eclipse Land: Like your
workspace but limited to what's relevant to your project). Ex:
HelloWorldProject if the name of the application you gave was HelloWorld
● .idea: This where project specific metadata is stored by Android Studio (AS).
(Eclipse Land: project.properties file)
● gradle: This is where the gradle build system's jar wrapper i.e. this jar is how
AS communicates with gradle installed in Windows (the OS in my case).
● External Libraries: This is not actually a folder but a place where Referenced
Libraries (Eclipse Land: Referenced Libraries) are shown. Here's where the
Targeted Platform is shown etc.
Top Level Folders
28
● Project Module: This is the actual project. ex: HelloWorld if your application
name you gave was HelloWorld.
⚪ build: This has all the complete output of the make process i.e. classes.
dex, compiled classes and resources
⚪ libs: This is the standard libs folder that you see in eclipse land too
⚪ src/AndroidManifest.xml: describes the fundamental characteristics of
the app and defines each of its components.
⚪ src/java: folder contains source code that implements the functionality
of your application.
⚪ src/res: folder contains various visual resources.
Top Level Folders
29
● Project Module: This is the actual project. ex: HelloWorld if your application
name you gave was HelloWorld.
⚪ src/res/layout: contains all files that define your app's user interface.
⚪ src/res/values: contains all XML files that contain a collection of
resources, such as strings and colors definitions.
⚪ src/res/drawbale-: contains drawable objects that are designed for each
screens according to their density.
⚪ src/assets: This is empty. You can use it to store raw asset files.
Top Level Folders
30
● AndroidManifest.xml is an interface between the Android OS and your
application.
What is AndroidManifest.xml?
31
What is AndroidManifest.xml?
32
Application Components
33
Intents, activities, services and broadcast receivers
● App components are the essential building blocks of an Android app. Each
component is a different point through which the system can enter your app.
● Not all components are actual entry points for the user and some depend on
each other, but each one exists as its own entity and plays a specific role
each one is a unique building block that helps define your app's overall
behavior.
● There are four different types of app components(Intents, activities,
services and broadcast receivers). Each type serves a distinct purpose and
has a distinct life cycle that defines how the component is created and
destroyed.
Application Components
34
Intents and Intent Filters
Application Components
35
● An Intent is a messaging object you can use to request an action from
another app component or communicate between other components like
activities, services or broadcast receivers.
What is an Intent?
36
● Although intents facilitate communication between components in several
ways, there are three fundamental use-cases:
⚪ To start activity
⚪ To start service
⚪ To deliver a broadcast
● There are two types of Intents:
⚪ Explicit Intents
⚪ Implicit Intents
What is an Intent?
37
Intents Types
Explicit intents:
● Used to start a component in your own app, because you know the class
name of the activity or service you want to start.
● For example, start a new activity in response to a user action or start a
service to download a file in the background.
38
Intents Types
39
Implicit intents:
● No specific component needed , but instead declare a general action to
perform, which allows a component from another app to handle it.
● For example, displaying user a location on a map can be done using
simple request allowing another capable app to show a it on a map.
Intent contains at least one of:
40
● Component name(optional): The name of the component to start. it's
the critical piece of information that makes an intent explicit, Without
a component name, the intent is implicit and the system decides which
component should receive the intent based on the other intent
information (such as the action, data, and category). So if you need to
start a specific component in your app, you should specify the
component name.
● Action(optional): A string that specifies the generic action to perform.
Intents Attributes
41
● Category(optional): A string containing additional information about the
kind of component that should handle the intent. Any number of
category descriptions can be placed in an intent, but most intents do
not require a category. Here are some common categories:
⚪ CATEGORY_BROWSABLE: The target activity allows itself to be
started by a web browser to display data referenced by a link.
⚪ CATEGORY_LAUNCHER: The activity is the initial activity of a task
and is listed in the system's application launcher.
Intents Attributes
42
● Data(optional): The URI (a Uri object) that references the data to be
acted on and/or the MIME type of that data. The type of data supplied is
generally dictated by the intent's action. For example, if the action is
ACTION_EDIT, the data should contain the URI of the document to edit.
● Extras(optional): Key-value pairs that carry additional information
required to accomplish the requested action. Just as some actions use
particular kinds of data URIs, some actions also use particular extras.
Intents Attributes
43
● Flags(optional): The flags may instruct the Android system how to
launch an activity (for example, which task the activity should belong
to) and how to treat it after it's launched (for example, whether it
belongs in the list of recent activities).
● Used to register specific component as being capable for doing specific action
on a set of data.
● To advertise which implicit intents your app can receive, declare one or more
intent filters for each of your app components with an <intent-filter>
element in your manifest file. Each intent filter specifies the type of intents
it accepts based on the intent's action, data, and category. The system will
deliver an implicit intent to your app component only if the intent can pass
through one of your intent filters.
● An explicit intent is always delivered to its target, regardless of any intent
filters the component declares
What is Intent Filter?
44
● Each intent filter is defined by an <intent-filter> element in the app's
manifest file, nested in the corresponding app component.
Example
45
46
Ready to code!
Activities
Application Components
47
An Activity is an application component that provides a single screen with which
users can interact in order to do something.
An application usually consists of multiple activities that are loosely bound to
each other. Each activity can start another activity in order to perform different
actions.
What is Activity?
48
Lifecycle
49
Example
50
How to use?
51
You can start an activity by calling startActivity(), passing it an Intent that
describes the activity you want to start. The intent specifies either the exact
activity you want to start or describes the type of action you want to perform
(and the system selects the appropriate activity for you, which can even be
from a different application). An intent can also carry small amounts of data to
be used by the activity that is started.
52
Ready to code!
Services
Application Components
53
● A service is a component that runs in the background to perform long-running
operations without needing to interact with the user.
● For example, a service might play music in the background while the user is
in a different application, or it might fetch data over the network without
blocking user interaction with an activity.
What is Service?
54
● A service can essentially take two forms:
a. Started(Unbounded): A service is "started" when an application
component (such as an activity) starts it by calling startService(). Once
started, a service can run in the background indefinitely, even if the
component that started it is destroyed. When the operation is done, the
service should stop itself.
Services Forms
55
● A service can essentially take two forms:
b. Bound: A service is "bound" when an application component binds to it by
calling bindService(). A bound service runs only as long as the
application component is bound to it. Multiple components can bind to
the service at once, but when all of them unbind, the service is
destroyed.
Services Forms(cont’)
56
● A service runs in the main thread of its hosting process.
● The service does not create its own thread and does not run in a separate
process (unless you specify otherwise). This means that, if your service is
going to do any CPU intensive work or blocking operations (such as MP3
playback or networking), you should create a new thread within the service
to do that work. By using a separate thread.
Lifecycle
57
Lifecycle(cont’)
58
● If the service is bound to an activity that has user focus, then it's less
likely to be killed, and if the service is declared to run in the
foreground, then it will almost never be killed. Otherwise, if the
service was started and is long-running, then the system will lower its
position in the list of background tasks over time and the service will
become highly susceptible to killing.
● if your service is started, then you must design it to gracefully handle
restarts by the system. If the system kills your service, it restarts it as
soon as resources become available again.
Lifecycle(cont’)
59
Example
60
Services: Started Service
Application Components
61
⚪ Service:
◾ Base class for all services. When this class is extended, it's important that
you create a new thread in which to do all the service's work.
⚪ IntentService:
◾ Subclass of Service that uses a worker thread to handle all start
requests, one at a time. This is the best option if you don't require that
your service handle multiple requests simultaneously. All you need to
do is implement onHandleIntent(), which receives the intent for each
start request so you can do the background work.
Started Service Forms
62
● Service:
⚪ It may block the Main Thread of the application.
● IntentService:
⚪ It cannot run tasks in parallel. Hence all the consecutive intents will go
into the message queue for the worker thread and will execute
sequentially.
⚪ It must be triggered from Main Thread.
Started Service Limitations
63
Is that means that anything done by IntentService can be done with a
Service?
IntentService instead of Service?
64
Is that means that anything done by IntentService can be done with a
Service?
If yes, then why IntentService?
Why IntentService?
65
Services: Bounded Service
Application Components
66
● A bound service is one that allows application components to bind to
it by calling bindService() in order to create a long-standing
connection.
● You should create a bound service when you want to interact with the
service from activities and other components in your application or to
expose some of your application's functionality to other applications
● To create a bound service, you must implement the onBind() callback
method to return an IBinder that defines the interface for
communication with the service. Other application components can
then call bindService() to retrieve the interface and begin calling
methods on the service.
What is Bounded Service?
67
● The bounded service lives only to serve the application component
that is bound to it, so when there are no components bound to the
service, the system destroys it.
What is Bounded Service?
68
Example
69
Download File from the internet on demand?
Which type of service to make this task?
70
Send info about specific file update change on the system?
Which type of service to make this task?
71
execute calculations for your application in background?
Which type of service to make this task?
72
73
Ready to code!
Broadcast Receivers
Application Components
74
● A broadcast receiver is a component that responds to system-wide broadcast
announcements.
What is Broadcast Receiver?
75
● Many broadcasts originate from the system for example, a broadcast
announcing that the screen has turned off, the battery is low, or a picture
was captured.
● Apps can also initiate broadcasts for example, 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 display a user interface.
● They may create a status bar notification to alert the user when a broadcast
event occurs.
● Broadcast receiver is just a "gateway" to other components and is intended to
do a very minimal amount of work. For instance, it might initiate a service to
perform some work based on the event.
What is Broadcast Receiver?
76
1. Normal broadcasts:
○ sent using sendBroadcast()
○ Are completely asynchronous.
○ All receivers of the broadcast are run in an undefined order, often at the
same time.
○ This basically means that one receiver can not interfere in any way with
what other receivers will do neither can it prevent other receivers from
being executed. One example of such broadcast is the
ACTION_BATTERY_LOW one.
Broadcast Receiver Types
77
2. Ordered broadcasts:
○ sent using sendOrderedBroadcast()
○ Delivered to one receiver at a time.
○ The order receivers run in can be controlled with the android:priority
attribute of the matching intent-filter; receivers with the same priority
will be run in an arbitrary order
○ ACTION_NEW_OUTGOING_CALL is a live example. This broadcast is sent
whenever the user tries to initiate a phone call. There are several
reasons that one would want to be notified about this,as
■ To be able to reject an outgoing call.
■ To be able to rewrite the number before it is dialed.
Broadcast Receiver Types
78
● A BroadcastReceiver object is only valid for the duration of the call to
onReceive(Context, Intent). Once your code returns from this function, the
system considers the object to be finished and no longer active.
● This has important repercussions to what you can do in an onReceive(Context,
Intent) implementation: anything that requires asynchronous operation is
not available, because you will need to return from the function to handle
the asynchronous operation, but at that point the BroadcastReceiver is no
longer active and thus the system is free to kill its process before the
asynchronous operation completes.
Lifecycle
79
● Display a Toast when user changes wallpaper
Example
80
81
Ready to code!
Thank You

More Related Content

What's hot

Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android Ranjith Kumar
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to androidzeelpatel0504
 
android architecture
android architectureandroid architecture
android architectureAashita Gupta
 
An introduction on Android OS, its working and android development
An introduction on Android OS, its working and android developmentAn introduction on Android OS, its working and android development
An introduction on Android OS, its working and android developmentSanskar Saraf
 
Introduction to Android
Introduction to AndroidIntroduction to Android
Introduction to AndroidOum Saokosal
 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecturedeepakshare
 
An introduction on Android OS, its working and android development
An introduction on Android OS, its working and android developmentAn introduction on Android OS, its working and android development
An introduction on Android OS, its working and android developmentSanskar Saraf
 
Android seminar report
Android seminar reportAndroid seminar report
Android seminar reportdgpune
 
Basic of Android App Development
Basic of Android App DevelopmentBasic of Android App Development
Basic of Android App DevelopmentAbhijeet Gupta
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application DevelopmentRamesh Prasad
 
Android Overview
Android OverviewAndroid Overview
Android Overviewatomi
 
Mobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaMobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaOsama Ghandour Geris
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorialmaster760
 
Introduction to Android - Mobile Portland
Introduction to Android - Mobile PortlandIntroduction to Android - Mobile Portland
Introduction to Android - Mobile Portlandsullis
 
Android Programming Seminar
Android Programming SeminarAndroid Programming Seminar
Android Programming SeminarNhat Nguyen
 

What's hot (19)

Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
android architecture
android architectureandroid architecture
android architecture
 
An introduction on Android OS, its working and android development
An introduction on Android OS, its working and android developmentAn introduction on Android OS, its working and android development
An introduction on Android OS, its working and android development
 
Introduction to Android
Introduction to AndroidIntroduction to Android
Introduction to Android
 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecture
 
Android report.
Android report.Android report.
Android report.
 
An introduction on Android OS, its working and android development
An introduction on Android OS, its working and android developmentAn introduction on Android OS, its working and android development
An introduction on Android OS, its working and android development
 
Android seminar report
Android seminar reportAndroid seminar report
Android seminar report
 
Basic of Android App Development
Basic of Android App DevelopmentBasic of Android App Development
Basic of Android App Development
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application Development
 
My android
My androidMy android
My android
 
Android Overview
Android OverviewAndroid Overview
Android Overview
 
Mobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaMobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osama
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Introduction to Android - Mobile Portland
Introduction to Android - Mobile PortlandIntroduction to Android - Mobile Portland
Introduction to Android - Mobile Portland
 
Gdsc android introduction
Gdsc android introductionGdsc android introduction
Gdsc android introduction
 
Android Programming Seminar
Android Programming SeminarAndroid Programming Seminar
Android Programming Seminar
 

Similar to Android Components Explained

Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app developmentAbhishekKumar4779
 
Mobile Application Development-Lecture 03 & 04.pdf
Mobile Application Development-Lecture 03 & 04.pdfMobile Application Development-Lecture 03 & 04.pdf
Mobile Application Development-Lecture 03 & 04.pdfAbdullahMunir32
 
Unit 1-android-and-its-tools-ass
Unit 1-android-and-its-tools-assUnit 1-android-and-its-tools-ass
Unit 1-android-and-its-tools-assARVIND SARDAR
 
Android Architecture and Working
Android Architecture and WorkingAndroid Architecture and Working
Android Architecture and WorkingAnkurVeer1
 
Android Technology
Android TechnologyAndroid Technology
Android TechnologyR
 
Android : Architecture & Components
Android : Architecture & ComponentsAndroid : Architecture & Components
Android : Architecture & ComponentsAkash Bisariya
 
Evolution of Android Operating System and it’s Versions
Evolution of Android Operating System and it’s VersionsEvolution of Android Operating System and it’s Versions
Evolution of Android Operating System and it’s Versionsijtsrd
 
Android deep dive
Android deep diveAndroid deep dive
Android deep diveAnuSahniNCI
 
Google android white paper
Google android white paperGoogle android white paper
Google android white paperSravan Reddy
 
Android development training programme Day 1
Android development training programme Day 1Android development training programme Day 1
Android development training programme Day 1DHIRAJ PRAVIN
 
OS in mobile devices [Android]
OS in mobile devices [Android]OS in mobile devices [Android]
OS in mobile devices [Android]Yatharth Aggarwal
 
Best Frameworks for Android App Development in 2022.pdf
Best Frameworks for Android App Development in 2022.pdfBest Frameworks for Android App Development in 2022.pdf
Best Frameworks for Android App Development in 2022.pdfMarie Weaver
 
Android overview
Android overviewAndroid overview
Android overviewHas Taiar
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answerskavinilavuG
 

Similar to Android Components Explained (20)

Seminar on android app development
Seminar on android app developmentSeminar on android app development
Seminar on android app development
 
Android
AndroidAndroid
Android
 
Android operating system
Android operating systemAndroid operating system
Android operating system
 
Mobile Application Development-Lecture 03 & 04.pdf
Mobile Application Development-Lecture 03 & 04.pdfMobile Application Development-Lecture 03 & 04.pdf
Mobile Application Development-Lecture 03 & 04.pdf
 
Android session 1
Android session 1Android session 1
Android session 1
 
Unit 1-android-and-its-tools-ass
Unit 1-android-and-its-tools-assUnit 1-android-and-its-tools-ass
Unit 1-android-and-its-tools-ass
 
Android
AndroidAndroid
Android
 
Android Architecture and Working
Android Architecture and WorkingAndroid Architecture and Working
Android Architecture and Working
 
Android Technology
Android TechnologyAndroid Technology
Android Technology
 
Android : Architecture & Components
Android : Architecture & ComponentsAndroid : Architecture & Components
Android : Architecture & Components
 
Evolution of Android Operating System and it’s Versions
Evolution of Android Operating System and it’s VersionsEvolution of Android Operating System and it’s Versions
Evolution of Android Operating System and it’s Versions
 
Android deep dive
Android deep diveAndroid deep dive
Android deep dive
 
Google android white paper
Google android white paperGoogle android white paper
Google android white paper
 
Android development training programme Day 1
Android development training programme Day 1Android development training programme Day 1
Android development training programme Day 1
 
OS in mobile devices [Android]
OS in mobile devices [Android]OS in mobile devices [Android]
OS in mobile devices [Android]
 
Android platform
Android platform Android platform
Android platform
 
Best Frameworks for Android App Development in 2022.pdf
Best Frameworks for Android App Development in 2022.pdfBest Frameworks for Android App Development in 2022.pdf
Best Frameworks for Android App Development in 2022.pdf
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Android overview
Android overviewAndroid overview
Android overview
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answers
 

Recently uploaded

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Android Components Explained

  • 1.
  • 2. From A to Z Android Hazem Hagrass Senior Software Engineer hazem.hagrass@badrit.com 2
  • 3. Agenda ● Overview ● Architecture ● Environment Setup ● Project Structure and modules ● Application Components ⚪ Intents and Filters ⚪ Activities ⚪ Services ⚪ Broadcast Receivers 3
  • 5. The Forgotten History ● Created by Andy Rubin, a free, open source mobile platform that any coder could write for and any handset maker could install. ● “There were nearly 700 million cell phones sold each year compared with fewer than 200 million PCs and the gap was widening. Increasingly, phones were the way people wanted to connect with each other and with everything else” Andy Rubin. 5
  • 6. The Forgotten History ● He would make his money by selling support for the system security services, or email management. 6
  • 7. The Forgotten History ● Rubin discussed the idea with Larry Page(Google's CEO), he didn’t want money from Page. He already had funding. What he wanted was Google’s imprimatur, even an email from Page would do. ● Rubin figured he could attract more VC funds with the search giant on board, possibly with a hint that Google might be interested in developing its own branded phone. He pulled out a prototype. 7
  • 8. The Forgotten History ● When Apple introduced the iPhone in 2007, Google was already working on Android, its own smartphone operating system. Google bought Android, which was Rubin's startup, for ~$50 million in 2005. 8
  • 10. Who is OHA? 10 ● The OHA was established on 6 November 2007 ● it is led by Google with 47 members including mobile handset makers, application developers, some mobile carriers and chip makers. ● Android, the flagship software of the alliance, is based on an open source license and has competed against mobile platforms from Apple (iOS), Microsoft, Nokia (Symbian), HP ( Palm), Samsung Electronics / Intel (Tizen, bada), and Blackberry.
  • 11. Steve Jobs! "Everything is a f**king rip off of what we're doing," Jobs said of Android 11
  • 12. Android powers hundreds of millions of mobile devices in more than 190 countries around the world. It's the largest installed base of any mobile platform and growing fast Android, the world's most popular mobile platform 12
  • 14. ● Every day more than 1 million new Android devices are activated worldwide. ● 1.5 billion downloads a month and growing. Get your apps in front of millions of users at Google's scale ● Android Nears 80% Market Share In Global Smartphone Shipments, As iOS And BlackBerry Share Slides, Per IDC Play Store 14
  • 15. Android is open! Android is Open, it is built on the open Linux Kernel. it can be liberally extended to incorporate new cutting edge technologies as they emerge. The platform will continue to evolve as the developer community works together to build innovative mobile applications. Android was built from the ground-up to enable developers take full advantage of all a handset has to offer. It was built to be truly open. For example, an application can call upon any of the phone’s core functionality such as making calls, sending text messages, or using the camera 15
  • 16. All applications are created equal Android does not differentiate between the phone’s core applications and third-party applications. They can all be built to have equal access to a phone’s capabilities providing users with a broad spectrum of applications and services Equality 16
  • 19. Linux Kernel ● The Android OS is derived from Linux Kernel 2.6 and is actually created from Linux source ● This provides basic system functionality like process management, memory management, device management like camera, keypad, display etc. Also, the kernel handles all the things that Linux is really good at such as networking and a vast array of device drivers, which take the pain out of interfacing to peripheral hardware. 19
  • 20. Libraries ● This layer holds the Android native libraries written in C/C++ and offer capabilities similar to the above layer, while sitting on top of the kernel. ● Set of libraries including open-source Web browser engine WebKit, well known library libc, SQLite database which is a useful repository for storage and sharing of application data, libraries to play and record audio and video, SSL libraries responsible for Internet security etc. 20
  • 21. It provides a key component called Dalvik Virtual Machine which is a kind of Java Virtual Machine specially designed and optimized for Android. When we say it is for embedded devices, it means it is low on memory, comparatively slower and runs on battery power. The Dalvik VM enables every Android application to run in its own process, with its own instance of the Dalvik virtual machine. The Android runtime also provides a set of core libraries which enable Android application developers to write Android applications using standard Java programming language. Android Runtime 21
  • 22. Application Framework It is the layer which application developers can leverage in developing Android applications. The framework offers a huge set of APIs used by developers for various standard purposes, so that they don't have to code every basic task.The framework consists of certain entities. 22
  • 23. Your application to be installed on this layer only. Examples of such applications are Contacts Books, Browser, Games etc. Applications 23
  • 25. Now everything is easy and can be done on one click just by download Android SDK tools which contains: ● Android Studio IDE ● Android SDK tools ● Android 5.0 (Lollipop) Platform ● Android 5.0 emulator system image with Google APIs Installation 25
  • 28. ● Main Project: This would be entire project context (Eclipse Land: Like your workspace but limited to what's relevant to your project). Ex: HelloWorldProject if the name of the application you gave was HelloWorld ● .idea: This where project specific metadata is stored by Android Studio (AS). (Eclipse Land: project.properties file) ● gradle: This is where the gradle build system's jar wrapper i.e. this jar is how AS communicates with gradle installed in Windows (the OS in my case). ● External Libraries: This is not actually a folder but a place where Referenced Libraries (Eclipse Land: Referenced Libraries) are shown. Here's where the Targeted Platform is shown etc. Top Level Folders 28
  • 29. ● Project Module: This is the actual project. ex: HelloWorld if your application name you gave was HelloWorld. ⚪ build: This has all the complete output of the make process i.e. classes. dex, compiled classes and resources ⚪ libs: This is the standard libs folder that you see in eclipse land too ⚪ src/AndroidManifest.xml: describes the fundamental characteristics of the app and defines each of its components. ⚪ src/java: folder contains source code that implements the functionality of your application. ⚪ src/res: folder contains various visual resources. Top Level Folders 29
  • 30. ● Project Module: This is the actual project. ex: HelloWorld if your application name you gave was HelloWorld. ⚪ src/res/layout: contains all files that define your app's user interface. ⚪ src/res/values: contains all XML files that contain a collection of resources, such as strings and colors definitions. ⚪ src/res/drawbale-: contains drawable objects that are designed for each screens according to their density. ⚪ src/assets: This is empty. You can use it to store raw asset files. Top Level Folders 30
  • 31. ● AndroidManifest.xml is an interface between the Android OS and your application. What is AndroidManifest.xml? 31
  • 33. Application Components 33 Intents, activities, services and broadcast receivers
  • 34. ● App components are the essential building blocks of an Android app. Each component is a different point through which the system can enter your app. ● Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role each one is a unique building block that helps define your app's overall behavior. ● There are four different types of app components(Intents, activities, services and broadcast receivers). Each type serves a distinct purpose and has a distinct life cycle that defines how the component is created and destroyed. Application Components 34
  • 35. Intents and Intent Filters Application Components 35
  • 36. ● An Intent is a messaging object you can use to request an action from another app component or communicate between other components like activities, services or broadcast receivers. What is an Intent? 36
  • 37. ● Although intents facilitate communication between components in several ways, there are three fundamental use-cases: ⚪ To start activity ⚪ To start service ⚪ To deliver a broadcast ● There are two types of Intents: ⚪ Explicit Intents ⚪ Implicit Intents What is an Intent? 37
  • 38. Intents Types Explicit intents: ● Used to start a component in your own app, because you know the class name of the activity or service you want to start. ● For example, start a new activity in response to a user action or start a service to download a file in the background. 38
  • 39. Intents Types 39 Implicit intents: ● No specific component needed , but instead declare a general action to perform, which allows a component from another app to handle it. ● For example, displaying user a location on a map can be done using simple request allowing another capable app to show a it on a map.
  • 40. Intent contains at least one of: 40 ● Component name(optional): The name of the component to start. it's the critical piece of information that makes an intent explicit, Without a component name, the intent is implicit and the system decides which component should receive the intent based on the other intent information (such as the action, data, and category). So if you need to start a specific component in your app, you should specify the component name. ● Action(optional): A string that specifies the generic action to perform.
  • 41. Intents Attributes 41 ● Category(optional): A string containing additional information about the kind of component that should handle the intent. Any number of category descriptions can be placed in an intent, but most intents do not require a category. Here are some common categories: ⚪ CATEGORY_BROWSABLE: The target activity allows itself to be started by a web browser to display data referenced by a link. ⚪ CATEGORY_LAUNCHER: The activity is the initial activity of a task and is listed in the system's application launcher.
  • 42. Intents Attributes 42 ● Data(optional): The URI (a Uri object) that references the data to be acted on and/or the MIME type of that data. The type of data supplied is generally dictated by the intent's action. For example, if the action is ACTION_EDIT, the data should contain the URI of the document to edit. ● Extras(optional): Key-value pairs that carry additional information required to accomplish the requested action. Just as some actions use particular kinds of data URIs, some actions also use particular extras.
  • 43. Intents Attributes 43 ● Flags(optional): The flags may instruct the Android system how to launch an activity (for example, which task the activity should belong to) and how to treat it after it's launched (for example, whether it belongs in the list of recent activities).
  • 44. ● Used to register specific component as being capable for doing specific action on a set of data. ● To advertise which implicit intents your app can receive, declare one or more intent filters for each of your app components with an <intent-filter> element in your manifest file. Each intent filter specifies the type of intents it accepts based on the intent's action, data, and category. The system will deliver an implicit intent to your app component only if the intent can pass through one of your intent filters. ● An explicit intent is always delivered to its target, regardless of any intent filters the component declares What is Intent Filter? 44
  • 45. ● Each intent filter is defined by an <intent-filter> element in the app's manifest file, nested in the corresponding app component. Example 45
  • 48. An Activity is an application component that provides a single screen with which users can interact in order to do something. An application usually consists of multiple activities that are loosely bound to each other. Each activity can start another activity in order to perform different actions. What is Activity? 48
  • 51. How to use? 51 You can start an activity by calling startActivity(), passing it an Intent that describes the activity you want to start. The intent specifies either the exact activity you want to start or describes the type of action you want to perform (and the system selects the appropriate activity for you, which can even be from a different application). An intent can also carry small amounts of data to be used by the activity that is started.
  • 54. ● A service is a component that runs in the background to perform long-running operations without needing to interact with the user. ● For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. What is Service? 54
  • 55. ● A service can essentially take two forms: a. Started(Unbounded): A service is "started" when an application component (such as an activity) starts it by calling startService(). Once started, a service can run in the background indefinitely, even if the component that started it is destroyed. When the operation is done, the service should stop itself. Services Forms 55
  • 56. ● A service can essentially take two forms: b. Bound: A service is "bound" when an application component binds to it by calling bindService(). A bound service runs only as long as the application component is bound to it. Multiple components can bind to the service at once, but when all of them unbind, the service is destroyed. Services Forms(cont’) 56
  • 57. ● A service runs in the main thread of its hosting process. ● The service does not create its own thread and does not run in a separate process (unless you specify otherwise). This means that, if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work. By using a separate thread. Lifecycle 57
  • 59. ● If the service is bound to an activity that has user focus, then it's less likely to be killed, and if the service is declared to run in the foreground, then it will almost never be killed. Otherwise, if the service was started and is long-running, then the system will lower its position in the list of background tasks over time and the service will become highly susceptible to killing. ● if your service is started, then you must design it to gracefully handle restarts by the system. If the system kills your service, it restarts it as soon as resources become available again. Lifecycle(cont’) 59
  • 62. ⚪ Service: ◾ Base class for all services. When this class is extended, it's important that you create a new thread in which to do all the service's work. ⚪ IntentService: ◾ Subclass of Service that uses a worker thread to handle all start requests, one at a time. This is the best option if you don't require that your service handle multiple requests simultaneously. All you need to do is implement onHandleIntent(), which receives the intent for each start request so you can do the background work. Started Service Forms 62
  • 63. ● Service: ⚪ It may block the Main Thread of the application. ● IntentService: ⚪ It cannot run tasks in parallel. Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially. ⚪ It must be triggered from Main Thread. Started Service Limitations 63
  • 64. Is that means that anything done by IntentService can be done with a Service? IntentService instead of Service? 64
  • 65. Is that means that anything done by IntentService can be done with a Service? If yes, then why IntentService? Why IntentService? 65
  • 67. ● A bound service is one that allows application components to bind to it by calling bindService() in order to create a long-standing connection. ● You should create a bound service when you want to interact with the service from activities and other components in your application or to expose some of your application's functionality to other applications ● To create a bound service, you must implement the onBind() callback method to return an IBinder that defines the interface for communication with the service. Other application components can then call bindService() to retrieve the interface and begin calling methods on the service. What is Bounded Service? 67
  • 68. ● The bounded service lives only to serve the application component that is bound to it, so when there are no components bound to the service, the system destroys it. What is Bounded Service? 68
  • 70. Download File from the internet on demand? Which type of service to make this task? 70
  • 71. Send info about specific file update change on the system? Which type of service to make this task? 71
  • 72. execute calculations for your application in background? Which type of service to make this task? 72
  • 75. ● A broadcast receiver is a component that responds to system-wide broadcast announcements. What is Broadcast Receiver? 75
  • 76. ● Many broadcasts originate from the system for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. ● Apps can also initiate broadcasts for example, 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 display a user interface. ● They may create a status bar notification to alert the user when a broadcast event occurs. ● Broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event. What is Broadcast Receiver? 76
  • 77. 1. Normal broadcasts: ○ sent using sendBroadcast() ○ Are completely asynchronous. ○ All receivers of the broadcast are run in an undefined order, often at the same time. ○ This basically means that one receiver can not interfere in any way with what other receivers will do neither can it prevent other receivers from being executed. One example of such broadcast is the ACTION_BATTERY_LOW one. Broadcast Receiver Types 77
  • 78. 2. Ordered broadcasts: ○ sent using sendOrderedBroadcast() ○ Delivered to one receiver at a time. ○ The order receivers run in can be controlled with the android:priority attribute of the matching intent-filter; receivers with the same priority will be run in an arbitrary order ○ ACTION_NEW_OUTGOING_CALL is a live example. This broadcast is sent whenever the user tries to initiate a phone call. There are several reasons that one would want to be notified about this,as ■ To be able to reject an outgoing call. ■ To be able to rewrite the number before it is dialed. Broadcast Receiver Types 78
  • 79. ● A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active. ● This has important repercussions to what you can do in an onReceive(Context, Intent) implementation: anything that requires asynchronous operation is not available, because you will need to return from the function to handle the asynchronous operation, but at that point the BroadcastReceiver is no longer active and thus the system is free to kill its process before the asynchronous operation completes. Lifecycle 79
  • 80. ● Display a Toast when user changes wallpaper Example 80