Activity and Fragment
Activity and Fragment
onStart()
When the activity enters the Started state, the system invokes onStart().
This call makes the activity visible to the user as the app prepares for the activity to enter
the foreground and become interactive.
For example, this method is where the code that maintains the UI is initialized.
onResume()
When the activity enters the Resumed state, it comes to the foreground, and the system
invokes the onResume() callback. This is the state in which the app interacts with the
user. The app stays in this state until something happens to take focus away from the app,
such as the device receiving a phone call, the user navigating to another activity, or the
device screen turning off.
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. It indicates that the activity
is no longer in the foreground
onStop()
When your activity is no longer visible to the user, it enters the Stopped state, and the
system invokes the onStop() callback. This can occur when a newly launched activity
covers the entire screen. The system also calls onStop() when the activity finishes running
and is about to be terminated.
onDestroy()
onDestroy() is called before the activity is destroyed. The system invokes this callback for
one of two reasons:
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, such as
device rotation or entering multi-window mode.
Fragment Lifecycle
Each Fragment instance has its own lifecycle. When a user navigates and interacts with your
app, your fragments transition through various states in their lifecycle as they are added,
removed, and enter or exit the screen.