SlideShare a Scribd company logo
1 of 19
Activity
1
Sourabh Sahu
?

What is started by the device

It contains the application's
information

Has method a to answer certain
events

An application could be composed
of multiple activities
Activity Life
Cycle

Resumed

The activity is in the foreground, and the user
can interact.

Paused

The activity is partially overlayed by another
activity. Cannot execute any code nor receive
inputs.

Stopped

Activity is hidden, in the background. It cannot
execute any code.
OnCreate()
 Called when the activity is
created
 Should contain the initialization
operations
 Has a Bundle parameter
 If onCreate() succesfull
terminates, it calls onStart()

OnStart()

Called when onCreate() terminates

Called right before it is visible to
user

If it has the focus, then onResume()
is called

If not, onStop() is called
OnResume()
 Called when the activity is
ready to get input from users
 Called when the activity is
resumed too
 If it succesfully terminates,
then the Activity is RUNNING

OnPause()

Called when another activity comes
to the foreground, or when
someone presses back

Commit unsaved changes to
persistent data

Stop cpu-consuming processes

Make it fast

OnRestart()

Similar to onCreate()

We have an activity that was
previously stopped
OnStop()
 Activity is no longer visible to the
user
 Could be called because:
 the activity is about to be
destroyed
 another activity comes to the
foreground
OnDestroy()
 The activity is about to be destroyed
 Could happen because:
 The systems need some stack space
 Someone called finish() method
on this activity
 Could check with isFinishing()
Mainly 3 different loops
Entire lifetime
 Between onCreate() and onDestroy().
 Setup of global state in onCreate()
 Release remaining resources in
onDestroy()
Visible lifetime
 Between onStart() and onStop().
 Maintain resources that has to be shown to
the user.
Foreground lifetime
 Between onResume() and onPause().
 Code should be light.
• Declare them before running them
• <activity android:name=".MainActivity"
android:label="@string/app_name">
• <intent-filter>
• <action
android:name="android.intent.action.MAIN"
/>
• <category
android:name="android.intent.category.LAUN
CHER" />
• </intent-filter>
• </activity>
In manifest file
• Open the MainActivity.java file in the
project, and override the
existing onStart method, which is called
when the activity is first viewed.
• Call the onStart method of the parent
class, and log a debug message:
• @Override
• public void onStart(){
super.onStart();
Log.d(CLASS_NAME, "onStart");
• }
• Override the existing onPause method,
which is called when another activity is
called to the foreground. Call
the onPause method of the parent and log
a debug message:
@Override
public void onPause(){
super.onPause();
Log.d(CLASS_NAME, "onPause");
}
• Override the existing onResume method, which is called
when the activity is running in the foreground and the user
can interact with it. Call the onResume method of the
parent class, and log a debug message:
• @Override public void onResume()
{ super.onResume();
• Log.d(CLASS_NAME, "onResume");
• }
Override the existing onStop method, which is called when the
activity is invisible to the end user. Call the onStop method of the
parent class, and log a debug message:
@Override public void onStop(){
super.onStop();
Log.d(CLASS_NAME, "onStop");
}
Override the existing onDestroy method, which is called when the
activity is removed from the system and can no longer be
interacted with. Call the onDestroy method of the parent class, and
log a debug message:
@Override public void onDestroy(){
super.onDestroy();
Log.d(CLASS_NAME, "onDestroy");
}
Override the existing onRestart method, which is called when the
activity is started again and returns to the foreground. Call
the onRestart method of the parent class and log a debug
message:
@Override public void onRestart(){
super.onRestart();
Log.d(CLASS_NAME, "onRestart"); }
Now Test & debug in Logcat
Thank You
19

More Related Content

Similar to Activities

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 Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdfssusere71a07
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android applicationNikunj Dhameliya
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
Lecture #4 activities &amp; fragments
Lecture #4  activities &amp; fragmentsLecture #4  activities &amp; fragments
Lecture #4 activities &amp; fragmentsVitali Pekelis
 
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
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - AndroidWingston
 
android activity
android activityandroid activity
android activityDeepa Rani
 
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 lifecycle
Android lifecycleAndroid lifecycle
Android lifecycleKumar
 
Android activity
Android activityAndroid activity
Android activityMohNage7
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 

Similar to Activities (20)

Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Android activity
Android activityAndroid activity
Android activity
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Lecture #4 activities &amp; fragments
Lecture #4  activities &amp; fragmentsLecture #4  activities &amp; fragments
Lecture #4 activities &amp; fragments
 
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
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
android activity
android activityandroid activity
android activity
 
Android - Message
Android - MessageAndroid - Message
Android - Message
 
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 lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android activity
Android activityAndroid activity
Android activity
 
Android
AndroidAndroid
Android
 
Activity lifecycle
Activity lifecycleActivity lifecycle
Activity lifecycle
 
Google android Activity lifecycle
Google android Activity lifecycle Google android Activity lifecycle
Google android Activity lifecycle
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 

More from Sourabh Sahu

Understanding GIT and Version Control
Understanding GIT and Version ControlUnderstanding GIT and Version Control
Understanding GIT and Version ControlSourabh Sahu
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization Sourabh Sahu
 
Mongo db Quick Guide
Mongo db Quick GuideMongo db Quick Guide
Mongo db Quick GuideSourabh Sahu
 
Android styles and themes
Android styles and themesAndroid styles and themes
Android styles and themesSourabh Sahu
 
SeekBar in Android
SeekBar in AndroidSeekBar in Android
SeekBar in AndroidSourabh Sahu
 
Android ListView and Custom ListView
Android ListView and Custom ListView Android ListView and Custom ListView
Android ListView and Custom ListView Sourabh Sahu
 
Android project architecture
Android project architectureAndroid project architecture
Android project architectureSourabh Sahu
 
Shared preferences
Shared preferencesShared preferences
Shared preferencesSourabh Sahu
 
Content Providers in Android
Content Providers in AndroidContent Providers in Android
Content Providers in AndroidSourabh Sahu
 
Calendar, Clocks, DatePicker and TimePicker
Calendar, Clocks, DatePicker and TimePickerCalendar, Clocks, DatePicker and TimePicker
Calendar, Clocks, DatePicker and TimePickerSourabh Sahu
 
Progress Dialog, AlertDialog, CustomDialog
Progress Dialog, AlertDialog, CustomDialogProgress Dialog, AlertDialog, CustomDialog
Progress Dialog, AlertDialog, CustomDialogSourabh Sahu
 
AutocompleteTextView And MultiAutoCompleteTextView
AutocompleteTextView And MultiAutoCompleteTextViewAutocompleteTextView And MultiAutoCompleteTextView
AutocompleteTextView And MultiAutoCompleteTextViewSourabh Sahu
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializableSourabh Sahu
 
Android Architecture
Android ArchitectureAndroid Architecture
Android ArchitectureSourabh Sahu
 
Android Installation Testing
Android Installation TestingAndroid Installation Testing
Android Installation TestingSourabh Sahu
 
Android Installation
Android Installation Android Installation
Android Installation Sourabh Sahu
 

More from Sourabh Sahu (20)

Understanding GIT and Version Control
Understanding GIT and Version ControlUnderstanding GIT and Version Control
Understanding GIT and Version Control
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization
 
Mongo db Quick Guide
Mongo db Quick GuideMongo db Quick Guide
Mongo db Quick Guide
 
Python Course
Python CoursePython Course
Python Course
 
Android styles and themes
Android styles and themesAndroid styles and themes
Android styles and themes
 
SeekBar in Android
SeekBar in AndroidSeekBar in Android
SeekBar in Android
 
Android layouts
Android layoutsAndroid layouts
Android layouts
 
Android ListView and Custom ListView
Android ListView and Custom ListView Android ListView and Custom ListView
Android ListView and Custom ListView
 
Android project architecture
Android project architectureAndroid project architecture
Android project architecture
 
Shared preferences
Shared preferencesShared preferences
Shared preferences
 
Content Providers in Android
Content Providers in AndroidContent Providers in Android
Content Providers in Android
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Calendar, Clocks, DatePicker and TimePicker
Calendar, Clocks, DatePicker and TimePickerCalendar, Clocks, DatePicker and TimePicker
Calendar, Clocks, DatePicker and TimePicker
 
Progress Dialog, AlertDialog, CustomDialog
Progress Dialog, AlertDialog, CustomDialogProgress Dialog, AlertDialog, CustomDialog
Progress Dialog, AlertDialog, CustomDialog
 
AutocompleteTextView And MultiAutoCompleteTextView
AutocompleteTextView And MultiAutoCompleteTextViewAutocompleteTextView And MultiAutoCompleteTextView
AutocompleteTextView And MultiAutoCompleteTextView
 
Web view
Web viewWeb view
Web view
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecture
 
Android Installation Testing
Android Installation TestingAndroid Installation Testing
Android Installation Testing
 
Android Installation
Android Installation Android Installation
Android Installation
 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“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...
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
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
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

Activities

  • 2. ?  What is started by the device  It contains the application's information  Has method a to answer certain events  An application could be composed of multiple activities
  • 4.
  • 5.  Resumed  The activity is in the foreground, and the user can interact.  Paused  The activity is partially overlayed by another activity. Cannot execute any code nor receive inputs.  Stopped  Activity is hidden, in the background. It cannot execute any code.
  • 6. OnCreate()  Called when the activity is created  Should contain the initialization operations  Has a Bundle parameter  If onCreate() succesfull terminates, it calls onStart()
  • 7.  OnStart()  Called when onCreate() terminates  Called right before it is visible to user  If it has the focus, then onResume() is called  If not, onStop() is called
  • 8. OnResume()  Called when the activity is ready to get input from users  Called when the activity is resumed too  If it succesfully terminates, then the Activity is RUNNING
  • 9.  OnPause()  Called when another activity comes to the foreground, or when someone presses back  Commit unsaved changes to persistent data  Stop cpu-consuming processes  Make it fast
  • 10.  OnRestart()  Similar to onCreate()  We have an activity that was previously stopped
  • 11. OnStop()  Activity is no longer visible to the user  Could be called because:  the activity is about to be destroyed  another activity comes to the foreground
  • 12. OnDestroy()  The activity is about to be destroyed  Could happen because:  The systems need some stack space  Someone called finish() method on this activity  Could check with isFinishing()
  • 13. Mainly 3 different loops Entire lifetime  Between onCreate() and onDestroy().  Setup of global state in onCreate()  Release remaining resources in onDestroy() Visible lifetime  Between onStart() and onStop().  Maintain resources that has to be shown to the user. Foreground lifetime  Between onResume() and onPause().  Code should be light.
  • 14. • Declare them before running them • <activity android:name=".MainActivity" android:label="@string/app_name"> • <intent-filter> • <action android:name="android.intent.action.MAIN" /> • <category android:name="android.intent.category.LAUN CHER" /> • </intent-filter> • </activity> In manifest file
  • 15. • Open the MainActivity.java file in the project, and override the existing onStart method, which is called when the activity is first viewed. • Call the onStart method of the parent class, and log a debug message: • @Override • public void onStart(){ super.onStart(); Log.d(CLASS_NAME, "onStart"); • }
  • 16. • Override the existing onPause method, which is called when another activity is called to the foreground. Call the onPause method of the parent and log a debug message: @Override public void onPause(){ super.onPause(); Log.d(CLASS_NAME, "onPause"); } • Override the existing onResume method, which is called when the activity is running in the foreground and the user can interact with it. Call the onResume method of the parent class, and log a debug message: • @Override public void onResume() { super.onResume(); • Log.d(CLASS_NAME, "onResume"); • }
  • 17. Override the existing onStop method, which is called when the activity is invisible to the end user. Call the onStop method of the parent class, and log a debug message: @Override public void onStop(){ super.onStop(); Log.d(CLASS_NAME, "onStop"); } Override the existing onDestroy method, which is called when the activity is removed from the system and can no longer be interacted with. Call the onDestroy method of the parent class, and log a debug message: @Override public void onDestroy(){ super.onDestroy(); Log.d(CLASS_NAME, "onDestroy"); } Override the existing onRestart method, which is called when the activity is started again and returns to the foreground. Call the onRestart method of the parent class and log a debug message: @Override public void onRestart(){ super.onRestart(); Log.d(CLASS_NAME, "onRestart"); }
  • 18. Now Test & debug in Logcat