Nothing Special   »   [go: up one dir, main page]

Activity Life Cycle

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

Android Activity

and
Activity Life Cycle
Android Activity:
• Activity is a single page application with some UI components.
• An activity is a Java file.
• We know that for every individual screen or activity in android we
need two things
1. XML File
2. Java File
• XML file is called as layout and Java file is called as activity.
• There are no. of stages are involved in activity phases so it called
as activity life cycle.
Android Activity Life Cycle:
Activity class is having some of major methods which will be
participate in an activity life cycle, these methods are shown below
1. onCreate()
2. onStart()
3. onResume()
4. onPause()
5. onStop()
6. onRestart()
7. onDestroy()
Android Activity Life Cycle (Continued….):
Android Activity Life Cycle (Continued….):
There are four states of an activity in activity life cycle.
1. Activity in does not exist state:
Means that activity currently is not started.
2. Activity is in foreground state:
• Whenever we are opening any application by using any
device, we see the home page of that application, means the
activity is in foreground state i.e. an activity comes from does
not exist state to foreground state.
• An activity comes from does not exist state to foreground state
by calling 3 major methods
onCreate(), onStart(), onResume()
• Above 3 major methods are invoked to start on activity.
• The current visible activity is destroyed by calling following 3
major methods
onPause(), onStop(), onDestroy()
Android Activity Life Cycle (Continued….):
3. Activity is in background state:
• Whenever we are opening any secondary page of an existing
application or opening another new application then some
other activity comes into foreground state and current visible
activity goes into background state.
• An activity goes from foreground state to background state by
calling following 2 major methods
onPause(), onStop()
• Above 2 major methods are invoked to turn a current activity
from foreground state to background state.
• A background state activity turns into a foreground state by
calling following 3 major methods
onRestart(), onStart(), onResume()
Android Activity Life Cycle (Continued….):
3. Activity is in background state:
• Whenever we are opening any secondary page of an existing
application or opening another new application then some
other activity comes into foreground state and current visible
activity goes into background state.
• An activity goes from foreground state to background state by
calling following 2 major methods
onPause(), onStop()
• Above 2 major methods are invoked to turn a current activity
from foreground state to background state.
• A background state activity turns into a foreground state by
calling following 3 major methods
onRestart(), onStart(), onResume()
Android Activity Life Cycle (Continued….):
4. Activity is in paused state:
• An activity turns or enters from foreground state to pause state
by calling onPause() method.
• An activity turns or enters from pause state to foreground state
by calling onResume() method.

You might also like