SlideShare a Scribd company logo
Romain	
  Chiappinelli	
  
The activity class
The activity class
The activity class
The task backstack
The activity lifecycle
Starting activities
Handling configuration changes
Provides a visual interface for user
interaction
Each activity typically supports one
focused thing a user can do, such as
Viewing an email message
Showing a login screen
Applications often comprise several
activities
Android supports navigation in several
ways:
Tasks
The task backstack
Suspending & resuming activities
A Task is a set of related Activities
These related activities don’t have to be
part of the same application
Most tasks start at the home screen
See: http://developer.android.com/guide/topics/

 
 
fundamentals/tasks-and-back-stack.html
When an Activity is launched, it goes on
top of the backstack
When the Activity is destroyed, it is
popped off the backstack
Activity 3
Activity 2
Activity 1
Activity 1
Activity 2Activity 1
Activities are created, suspended,
resumed & destroyed as necessary when
an application executes
Some of these actions depend on user
behavior
Some depend on Android
e.g., Android can kill activities when it
needs their resources
Resumed/Running - visible, user
interacting
Paused - visible, user not interacting,
can be terminated*
Stopped - not visible, can be
terminated
Android announces activity lifecycle
state changes to activity by calling
specific activity methods
protected void onCreate (Bundle savedInstanceState)
protected void onStart()
protected void onResume()
protected void onPause()
protected void onRestart()
protected void onStop()
protected void onDestroy()
The activity class
The activity class
Entire
Lifetime
Visible
Visible & in
Foreground
The activity class
 	
  
The activity class
The activity class
Called when Activity is created
Sets up Initial state
Call super.onCreate()
Set the Activity’s content view
Retain references to UI views as
necessary
Configure views as necessary
MapLocation
Called if the Activity has been stopped
and is about to be started again
Typical actions
Special processing needed only after
having been stopped
Activity is about to become visible
Typical actions
Start when visible-only behaviors
Loading persistent application state
Activity is visible and about to start
interacting with user
Typical actions
Start foreground-only behaviors
Focus about to switch to another
Activity
Typical actions
Shutdown foreground-only behaviors
Save persistent state
Activity is no longer visible to user
may be restarted later
Typical actions
Cache state
Note: may not be called if Android
kills your application
Activity is about to be destroyed
Typical actions
Release Activity resources
Note: may not be called if Android
kills your application
MapLocation
MapLocation
Create an Intent object specifying the
Activity to start
Pass newly created Intent to methods,
such as:
startActivity()
startActivityForResult() 
Invokes a Callback method when
the called Activity finishes to return
a result
MapLocation
Similar to MapLocation, but gets
address from contacts database
The activity class
MapLocationFromContacts
Started Activity can set its result by
calling Activity.setResult()
public final void setResult (int resultCode)
public final void setResult (int resultCode,

 
 
 
 
 Intent data)
resultCode (an int)
RESULT_CANCELED
RESULT_OK
RESULT_FIRST_USER
Custom resultCodes can be added
MapLocationFromContacts
MapLocationFromContacts
Keyboard, orientation, locale, etc.
Device configuration can change at
runtime
On configuration changes, Android
usually kills the current Activity &
then restarts it
Activity restarting should be fast
If necessary you can:
Retain an Object containing important
state information during a configuration
change
Manually handle the configuration
change
Hard to recompute data can be cached
to speed up handling of configuration
changes
Override
onRetainNonConfigurationInstance() to
build & return configuration Object
Will be called between onStop() and
onDestroy()
Call getLastNonConfigurationInstance()
during onCreate() to recover retained
Object
Note: These methods have been deprecated
in favor of methods in the Fragment class
(discussed in later classes)
Can prevent system from restarting
Activity
Declare the configuration changes
your Activity handles in
AndroidManifest.xml file, e.g.,
<activity android:name=".MyActivity“"
android:configChanges="

"orientation|screensize|keyboardHidden”…>
When configuration changes,
Activity’ s onConfigurationChanged()
method is called
Passed a Configuration object
specifying the new device configuration
The Intent Class

More Related Content

PDF
Android activity
PPT
Android activity, service, and broadcast recievers
PDF
Lecture 3 getting active through activities
PDF
Android platform activity
ODP
Android App Development - 02 Activity and intent
PPTX
Unit 5 Activity and Activity Life Cycle.pptx
ODP
Anatomy of android application
PPTX
Android activity
Android activity
Android activity, service, and broadcast recievers
Lecture 3 getting active through activities
Android platform activity
Android App Development - 02 Activity and intent
Unit 5 Activity and Activity Life Cycle.pptx
Anatomy of android application
Android activity

Similar to The activity class (20)

PDF
Android activities & views
PDF
Android activity
DOCX
Android building blocks and application life cycle-chapter3
PDF
02 programmation mobile - android - (activity, view, fragment)
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
PDF
Android Basic Components
PDF
android_mod_3.useful for bca students for their last sem
PPTX
App Fundamentals and Activity life cycle.pptx
PPT
android activity
PDF
Android development Training Programme Day 2
PPT
DOCX
Android Application Components with Implementation & Examples
PPTX
Dori waldman android _course
PPTX
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
PPTX
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
PPTX
Android Developer Training
PPTX
Android application componenets for android app development
PPTX
Android Component.pptx
PPTX
Activity lifecycle
PDF
Android Jumpstart Jfokus
Android activities & views
Android activity
Android building blocks and application life cycle-chapter3
02 programmation mobile - android - (activity, view, fragment)
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
Android Basic Components
android_mod_3.useful for bca students for their last sem
App Fundamentals and Activity life cycle.pptx
android activity
Android development Training Programme Day 2
Android Application Components with Implementation & Examples
Dori waldman android _course
Unit-1.2 Android-Activities, Fragments, and Intents (1).pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
Android Developer Training
Android application componenets for android app development
Android Component.pptx
Activity lifecycle
Android Jumpstart Jfokus
Ad

More from maamir farooq (20)

DOCX
Ooad lab1
PPT
Lesson 03
PPT
Lesson 02
PDF
Php client libray
PDF
Swiftmailer
PDF
PDF
PPTX
PDF
PDF
J query 1.7 cheat sheet
PDF
Assignment
PDF
Java script summary
PDF
PDF
PPTX
PPTX
Css summary
DOCX
Manual of image processing lab
PDF
Session management
PDF
Data management
PPTX
Content provider
Ooad lab1
Lesson 03
Lesson 02
Php client libray
Swiftmailer
J query 1.7 cheat sheet
Assignment
Java script summary
Css summary
Manual of image processing lab
Session management
Data management
Content provider
Ad

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Lesson notes of climatology university.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Classroom Observation Tools for Teachers
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Institutional Correction lecture only . . .
human mycosis Human fungal infections are called human mycosis..pptx
Insiders guide to clinical Medicine.pdf
O7-L3 Supply Chain Operations - ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
Anesthesia in Laparoscopic Surgery in India
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
VCE English Exam - Section C Student Revision Booklet
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Lesson notes of climatology university.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Basic Mud Logging Guide for educational purpose
Classroom Observation Tools for Teachers
01-Introduction-to-Information-Management.pdf
Final Presentation General Medicine 03-08-2024.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Microbial disease of the cardiovascular and lymphatic systems
Institutional Correction lecture only . . .

The activity class