SlideShare a Scribd company logo
1 of 18
ANDROID
DEVELOPMENT
SESSION 2 – INTENT AND ACTIVITY
AHMED EZZ EL - DIN
facebook.com/ahmed.e.hassan
1
SESSION CONTENT
• Intent
• Activity
facebook.com/ahmed.e.hassan
2
INTENT
facebook.com/ahmed.e.hassan
3
An Intent is a messaging object you can use to request an action from another app
component.
Although intents facilitate communication between components in several ways,
there are three fundamental use-cases:
To start an activity
To start a service
To deliver a broadcast
An Activity represents a single screen in an app. You can start a new instance of an Activity by passing
an Intent to startActivity(). The Intent describes the activity to start and carries any necessary data.
A Service is a component that performs operations in the background without a user interface. You can
start a service to perform a one-time operation (such as download a file) by passing an Intent to
startService().
A broadcast is a message that any app can receive. The system delivers various broadcasts for system
events, such as when the system boots up or the device starts charging.
INTENT
facebook.com/ahmed.e.hassan
4
Intent Types
Explicit intents
specify the component to start by name (the fully-qualified class name). You'll typically use an
explicit intent 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.
Implicit intents
do not name a specific component, but instead declare a general action to perform, which allows
a component from another app to handle it. For example, if you want to show the user a location
on a map, you can use an implicit intent to request that another capable app show a specified
location on a map.
INTENT
facebook.com/ahmed.e.hassan
5
Illustration of how an implicit intent is delivered through the system to start another activity:
[1] Activity A creates an Intent with an action description and passes it to startActivity().
[2] The Android System searches all apps for an intent filter that matches the intent. When
a match is found,
[3] the system starts the matching activity (Activity B) by invoking its onCreate() method
and passing it the Intent.
INTENT
facebook.com/ahmed.e.hassan
6
Building an Intent
An Intent object carries information that the Android system uses to determine which component to
start, plus information that the recipient component uses in order to properly perform the action
The primary information contained in an Intent is the following:
Component name The name of the component to start.
Action A string that specifies the generic action to perform (such as view or pick).
Data 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.
Category 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.
Extras 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.
Flags Flags defined in the Intent class that function as metadata for the intent. 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).
ACTIVITY
facebook.com/ahmed.e.hassan
7
An Activity is an application component that provides a screen with which users
can interact in order to do something, such as dial the phone, take a photo, send
an email, or view a map.
Each activity is given a window in which to draw its user interface.
The window typically fills the screen, but may be smaller than the screen and
float on top of other windows.
An application usually consists of multiple activities that are loosely bound to
each other.
ACTIVITY
facebook.com/ahmed.e.hassan
8
Typically, one activity in an application is specified as the "main" activity, which
is presented to the user when launching the application for the first time.
Each activity can then start another activity in order to perform different actions.
Each time a new activity starts, the previous activity is stopped, but the system
preserves the activity in a stack (the "back stack").
When a new activity starts, it is pushed onto the back stack and takes user
focus. The back stack abides to the basic "last in, first out" stack mechanism,
so, when the user is done with the current activity and presses the Back
button, it is popped from the stack (and destroyed) and the previous activity
resumes.
ACTIVITY
facebook.com/ahmed.e.hassan
9
When an activity is stopped because a new activity starts, it is notified of this
change in state through the activity's lifecycle callback methods.
When stopped, your activity should release any large objects, such as network or
database connections.
When the activity resumes, you can reacquire the necessary resources and
resume actions that were interrupted. These state transitions are all part of the
activity lifecycle.
ACTIVITY
facebook.com/ahmed.e.hassan
10
Creating an Activity
To create an activity, you must create a subclass of Activity (or an existing subclass of it). In your
subclass, you need to implement callback methods that the system calls when the activity transitions
between various states of its lifecycle, such as when the activity is being created, stopped, resumed, or
destroyed. The two most important callback methods are:
onCreate()
You must implement this method. The system calls this when creating your activity. Within your
implementation, you should initialize the essential components of your activity. Most importantly,
this is where you must call setContentView() to define the layout for the activity's user interface.
onPause()
The system calls this method as the first indication that the user is leaving your activity (though it
does not always mean the activity is being destroyed). This is usually where you should commit
any changes that should be persisted beyond the current user session
ACTIVITY
facebook.com/ahmed.e.hassan
11
Declaring the activity in the manifest
You must declare your activity in the manifest file in order for it to be accessible to the system.
To declare your activity, open your manifest file and add an <activity> element as a child of the
<application> element. For example:
ACTIVITY
facebook.com/ahmed.e.hassan
12
Using intent filters
An <activity> element can also specify various intent filters—using the <intent-filter> element—in
order to declare how other application components may activate it.
ACTIVITY
facebook.com/ahmed.e.hassan
13
Starting an Activity
You can start another activity by calling startActivity(), passing it an Intent that describes the
activity you want to start.
However, your application might also want to perform some action, such as send an email,
text message, or status update, using data from your activity.
ACTIVITY
facebook.com/ahmed.e.hassan
14
Shutting Down an Activity
You can shut down an activity by calling its finish() method. You can also shut down a
separate activity that you previously started by calling finishActivity().
ACTIVITY
facebook.com/ahmed.e.hassan
15
Managing the Activity Lifecycle
An activity can exist in essentially three states:
Resumed
The activity is in the foreground of the screen and has user focus. (This state is also
sometimes referred to as "running".)
Paused
Another activity is in the foreground and has focus, but this one is still visible. That is, another
activity is visible on top of this one and that activity is partially transparent or doesn't cover the
entire screen.
Stopped
The activity is completely obscured by another activity (the activity is now in the "background").
A stopped activity is also still alive (the Activity object is retained in memory, it maintains all
state and member information, but is not attached to the window manager).
ACTIVITY
facebook.com/ahmed.e.hassan
16
Implementing the lifecycle callbacks
facebook.com/ahmed.e.hassan
17
facebook.com/ahmed.e.hassan
18
The two ways in which an activity returns to user focus with its state intact: either the activity is
destroyed, then recreated and the activity must restore the previously saved state, or the
activity is stopped, then resumed and the activity state remains intact.

More Related Content

What's hot

Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & IntentsLope Emano
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestateOsahon Gino Ediagbonya
 
android activity
android activityandroid activity
android activityDeepa Rani
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)Oum Saokosal
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in androidOum Saokosal
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recieversUtkarsh Mankad
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & viewsma-polimi
 
Android App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAndroid App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAnuchit Chalothorn
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycleKumar
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 

What's hot (20)

Android intents
Android intentsAndroid intents
Android intents
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
05 intent
05 intent05 intent
05 intent
 
Intents are Awesome
Intents are AwesomeIntents are Awesome
Intents are Awesome
 
android activity
android activityandroid activity
android activity
 
08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)08.1. Android How to Use Intent (explicit)
08.1. Android How to Use Intent (explicit)
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android activity
Android activityAndroid activity
Android activity
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Android Components
Android ComponentsAndroid Components
Android Components
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Android UI Fundamentals part 1
Android UI Fundamentals part 1Android UI Fundamentals part 1
Android UI Fundamentals part 1
 
Android App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; ShareAndroid App Development 07 : Intent &amp; Share
Android App Development 07 : Intent &amp; Share
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Lab1-android
Lab1-androidLab1-android
Lab1-android
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 

Viewers also liked

Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material DesignYasin Yildirim
 
CS Lesson: Introduction to the Java virtual Machine
CS Lesson: Introduction to the Java virtual MachineCS Lesson: Introduction to the Java virtual Machine
CS Lesson: Introduction to the Java virtual MachineKatrin Becker
 
Optimizing Apps for Better Performance
Optimizing Apps for Better PerformanceOptimizing Apps for Better Performance
Optimizing Apps for Better PerformanceElif Boncuk
 
Optimizing apps for better performance extended
Optimizing apps for better performance extended Optimizing apps for better performance extended
Optimizing apps for better performance extended Elif Boncuk
 
Workhsop on Logic Building for Programming
Workhsop on Logic Building for ProgrammingWorkhsop on Logic Building for Programming
Workhsop on Logic Building for ProgrammingAdarsh Patel
 
Project Analysis - How to Start Project Develoment
Project Analysis - How to Start Project DevelomentProject Analysis - How to Start Project Develoment
Project Analysis - How to Start Project DevelomentAdarsh Patel
 
Workshop on Search Engine Optimization
Workshop on Search Engine OptimizationWorkshop on Search Engine Optimization
Workshop on Search Engine OptimizationAdarsh Patel
 
Hack'n Break Android Workshop
Hack'n Break Android WorkshopHack'n Break Android Workshop
Hack'n Break Android WorkshopElif Boncuk
 
Lecture 04. Mobile App Design
Lecture 04. Mobile App DesignLecture 04. Mobile App Design
Lecture 04. Mobile App DesignMaksym Davydov
 
What's new in Android at I/O'16
What's new in Android at I/O'16What's new in Android at I/O'16
What's new in Android at I/O'16Elif Boncuk
 
Overview of DroidCon UK 2015
Overview of DroidCon UK 2015 Overview of DroidCon UK 2015
Overview of DroidCon UK 2015 Elif Boncuk
 
Android Udacity Study group 1
Android Udacity Study group 1Android Udacity Study group 1
Android Udacity Study group 1Aly Abdelkareem
 
Fundamental of android
Fundamental of androidFundamental of android
Fundamental of androidAdarsh Patel
 
Intent in android
Intent in androidIntent in android
Intent in androidDurai S
 
Working better together designers &amp; developers
Working better together   designers &amp; developersWorking better together   designers &amp; developers
Working better together designers &amp; developersVitali Pekelis
 
Session #8 adding magic to your app
Session #8  adding magic to your appSession #8  adding magic to your app
Session #8 adding magic to your appVitali Pekelis
 

Viewers also liked (20)

Activity
ActivityActivity
Activity
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material Design
 
CS Lesson: Introduction to the Java virtual Machine
CS Lesson: Introduction to the Java virtual MachineCS Lesson: Introduction to the Java virtual Machine
CS Lesson: Introduction to the Java virtual Machine
 
Optimizing Apps for Better Performance
Optimizing Apps for Better PerformanceOptimizing Apps for Better Performance
Optimizing Apps for Better Performance
 
App indexing api
App indexing apiApp indexing api
App indexing api
 
Optimizing apps for better performance extended
Optimizing apps for better performance extended Optimizing apps for better performance extended
Optimizing apps for better performance extended
 
Workhsop on Logic Building for Programming
Workhsop on Logic Building for ProgrammingWorkhsop on Logic Building for Programming
Workhsop on Logic Building for Programming
 
Project Analysis - How to Start Project Develoment
Project Analysis - How to Start Project DevelomentProject Analysis - How to Start Project Develoment
Project Analysis - How to Start Project Develoment
 
Workshop on Search Engine Optimization
Workshop on Search Engine OptimizationWorkshop on Search Engine Optimization
Workshop on Search Engine Optimization
 
Hack'n Break Android Workshop
Hack'n Break Android WorkshopHack'n Break Android Workshop
Hack'n Break Android Workshop
 
Lecture 04. Mobile App Design
Lecture 04. Mobile App DesignLecture 04. Mobile App Design
Lecture 04. Mobile App Design
 
What's new in Android at I/O'16
What's new in Android at I/O'16What's new in Android at I/O'16
What's new in Android at I/O'16
 
Android development session 3 - layout
Android development   session 3 - layoutAndroid development   session 3 - layout
Android development session 3 - layout
 
Overview of DroidCon UK 2015
Overview of DroidCon UK 2015 Overview of DroidCon UK 2015
Overview of DroidCon UK 2015
 
Android Udacity Study group 1
Android Udacity Study group 1Android Udacity Study group 1
Android Udacity Study group 1
 
Android development session 4 - Fragments
Android development   session 4 - FragmentsAndroid development   session 4 - Fragments
Android development session 4 - Fragments
 
Fundamental of android
Fundamental of androidFundamental of android
Fundamental of android
 
Intent in android
Intent in androidIntent in android
Intent in android
 
Working better together designers &amp; developers
Working better together   designers &amp; developersWorking better together   designers &amp; developers
Working better together designers &amp; developers
 
Session #8 adding magic to your app
Session #8  adding magic to your appSession #8  adding magic to your app
Session #8 adding magic to your app
 

Similar to Android development session 2 - intent and activity

android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semaswinbiju1652
 
Android Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsAndroid Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsDenis Minja
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx34ShreyaChauhan
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 
Android application fundamentals
Android application fundamentalsAndroid application fundamentals
Android application fundamentalsJohn Smith
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentalsAmr Salman
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database faiz324545
 
Android application development
Android application developmentAndroid application development
Android application developmentMd. Mujahid Islam
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Android application model
Android application modelAndroid application model
Android application modelmagicshui
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerAhsanul Karim
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2Tadas Jurelevičius
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxShantanuDharekar
 

Similar to Android development session 2 - intent and activity (20)

android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Android Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intentsAndroid Bootcamp Tanzania:intents
Android Bootcamp Tanzania:intents
 
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxxMAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
MAD Unit 5.pptxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 
Android application fundamentals
Android application fundamentalsAndroid application fundamentals
Android application fundamentals
 
Unit2
Unit2Unit2
Unit2
 
Android intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
 
ANDROID
ANDROIDANDROID
ANDROID
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentals
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
Android application development
Android application developmentAndroid application development
Android application development
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Android application model
Android application modelAndroid application model
Android application model
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation Primer
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 

Android development session 2 - intent and activity

  • 1. ANDROID DEVELOPMENT SESSION 2 – INTENT AND ACTIVITY AHMED EZZ EL - DIN facebook.com/ahmed.e.hassan 1
  • 2. SESSION CONTENT • Intent • Activity facebook.com/ahmed.e.hassan 2
  • 3. INTENT facebook.com/ahmed.e.hassan 3 An Intent is a messaging object you can use to request an action from another app component. Although intents facilitate communication between components in several ways, there are three fundamental use-cases: To start an activity To start a service To deliver a broadcast An Activity represents a single screen in an app. You can start a new instance of an Activity by passing an Intent to startActivity(). The Intent describes the activity to start and carries any necessary data. A Service is a component that performs operations in the background without a user interface. You can start a service to perform a one-time operation (such as download a file) by passing an Intent to startService(). A broadcast is a message that any app can receive. The system delivers various broadcasts for system events, such as when the system boots up or the device starts charging.
  • 4. INTENT facebook.com/ahmed.e.hassan 4 Intent Types Explicit intents specify the component to start by name (the fully-qualified class name). You'll typically use an explicit intent 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. Implicit intents do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it. For example, if you want to show the user a location on a map, you can use an implicit intent to request that another capable app show a specified location on a map.
  • 5. INTENT facebook.com/ahmed.e.hassan 5 Illustration of how an implicit intent is delivered through the system to start another activity: [1] Activity A creates an Intent with an action description and passes it to startActivity(). [2] The Android System searches all apps for an intent filter that matches the intent. When a match is found, [3] the system starts the matching activity (Activity B) by invoking its onCreate() method and passing it the Intent.
  • 6. INTENT facebook.com/ahmed.e.hassan 6 Building an Intent An Intent object carries information that the Android system uses to determine which component to start, plus information that the recipient component uses in order to properly perform the action The primary information contained in an Intent is the following: Component name The name of the component to start. Action A string that specifies the generic action to perform (such as view or pick). Data 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. Category 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. Extras 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. Flags Flags defined in the Intent class that function as metadata for the intent. 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).
  • 7. ACTIVITY facebook.com/ahmed.e.hassan 7 An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows. An application usually consists of multiple activities that are loosely bound to each other.
  • 8. ACTIVITY facebook.com/ahmed.e.hassan 8 Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time. Each activity can then start another activity in order to perform different actions. Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack (the "back stack"). When a new activity starts, it is pushed onto the back stack and takes user focus. The back stack abides to the basic "last in, first out" stack mechanism, so, when the user is done with the current activity and presses the Back button, it is popped from the stack (and destroyed) and the previous activity resumes.
  • 9. ACTIVITY facebook.com/ahmed.e.hassan 9 When an activity is stopped because a new activity starts, it is notified of this change in state through the activity's lifecycle callback methods. When stopped, your activity should release any large objects, such as network or database connections. When the activity resumes, you can reacquire the necessary resources and resume actions that were interrupted. These state transitions are all part of the activity lifecycle.
  • 10. ACTIVITY facebook.com/ahmed.e.hassan 10 Creating an Activity To create an activity, you must create a subclass of Activity (or an existing subclass of it). In your subclass, you need to implement callback methods that the system calls when the activity transitions between various states of its lifecycle, such as when the activity is being created, stopped, resumed, or destroyed. The two most important callback methods are: onCreate() You must implement this method. The system calls this when creating your activity. Within your implementation, you should initialize the essential components of your activity. Most importantly, this is where you must call setContentView() to define the layout for the activity's user interface. onPause() The system calls this method as the first indication that the user is leaving your activity (though it does not always mean the activity is being destroyed). This is usually where you should commit any changes that should be persisted beyond the current user session
  • 11. ACTIVITY facebook.com/ahmed.e.hassan 11 Declaring the activity in the manifest You must declare your activity in the manifest file in order for it to be accessible to the system. To declare your activity, open your manifest file and add an <activity> element as a child of the <application> element. For example:
  • 12. ACTIVITY facebook.com/ahmed.e.hassan 12 Using intent filters An <activity> element can also specify various intent filters—using the <intent-filter> element—in order to declare how other application components may activate it.
  • 13. ACTIVITY facebook.com/ahmed.e.hassan 13 Starting an Activity You can start another activity by calling startActivity(), passing it an Intent that describes the activity you want to start. However, your application might also want to perform some action, such as send an email, text message, or status update, using data from your activity.
  • 14. ACTIVITY facebook.com/ahmed.e.hassan 14 Shutting Down an Activity You can shut down an activity by calling its finish() method. You can also shut down a separate activity that you previously started by calling finishActivity().
  • 15. ACTIVITY facebook.com/ahmed.e.hassan 15 Managing the Activity Lifecycle An activity can exist in essentially three states: Resumed The activity is in the foreground of the screen and has user focus. (This state is also sometimes referred to as "running".) Paused Another activity is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this one and that activity is partially transparent or doesn't cover the entire screen. Stopped The activity is completely obscured by another activity (the activity is now in the "background"). A stopped activity is also still alive (the Activity object is retained in memory, it maintains all state and member information, but is not attached to the window manager).
  • 18. facebook.com/ahmed.e.hassan 18 The two ways in which an activity returns to user focus with its state intact: either the activity is destroyed, then recreated and the activity must restore the previously saved state, or the activity is stopped, then resumed and the activity state remains intact.