Unit-3
Unit-3
GTU # 3170726
onStart()
It is invoked when the activity is visible to the user.
It is followed by onResume() if the activity is invoked from the background.
It is also invoked after onCreate() when the activity is first started.
onRestart()
It is invoked after the activity has been stopped and prior to its starting stage.
Thus is always followed by onStart() when any activity is revived from background to on-screen.
Activity Life Cycle Contd.
onResume()
It is invoked when the activity starts interacting with the user.
At this point, the activity is at the top of the activity stack, with a user interacting with it.
Always followed by onPause() when the activity goes into the background or is closed by the user.
onPause()
It is invoked when an activity is going into the background but has not yet been killed.
It is a counterpart to onResume().
When an activity is launched in front of another activity, this callback will be invoked on the top activity
(currently on screen).
The activity, under the active activity, will not be created until the active activity’s onPause() returns, so it is
recommended that heavy processing should not be done in this part.
onStop()
It is invoked when the activity is not visible to the user.
It is followed by onRestart() when the activity is revoked from the background, followed by onDestroy().
Activity Life Cycle Contd.
onDestroy()
onDestroy() is called before the activity is destroyed.
The activity is finishing due to the user completely dismissing the activity or due to finish() being called on
the activity.
The system is temporarily destroying the activity due to a configuration change ex. device rotation or multi-
window mode.
Intents
An intent is to perform an action on the screen.
It is mostly used to start activity, send broadcast receiver, start services and send message
between two activities.
It is a messaging object which tells what kind of action to be performed.
The intent’s most significant use is the launching of the activity.
Body of Intent:
action: The general action to be performed, such as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
data: The data to operate on, such as a person record in the contacts database, expressed as a Uri
Basically two intents are there in android.
Implicit Intents
Explicit Intents
Implicit Intent
Implicit Intent doesn’t specify the component.
In such a case, intent provides information on available components provided by the system
that is to be invoked.
Implicit intents are used without a class name, where Android will help determine an
appropriate Activity to handle the intent.
For example, you may write the following code to view the webpage.
onStart():
The onStart() method is called once the fragment gets visible.
onResume():
Fragment becomes active.
onPause():
The system calls this method as the first indication that the user is leaving the fragment.
This is usually where you should commit any changes that should be persisted beyond the current user
session.
Fragment Life Cycle
onStop():
Fragment going to be stopped by calling onStop().
onDestroyView():
Fragment view will destroy after call this method.
onDestroy():
onDestroy() called to do final clean up of the fragment's state but Not guaranteed to be called by the Android
platform.
Mobile Application Development (MAD)
GTU # 3170726
Thank You