An activity defines a single, focused thing that the user can do.
An example of an activity is downloading a file from Google Drive or Microsoft OneDrive.
To implement an Android Activity, the class must extend the Activity class. The Activity class is a common interface for user interaction. It contains the following methods:
onStart()
onRestart()
onResume()
onPause()
onStop()
onDestroy()
The methods in the Activity class are part of the Activity Lifecycle and are called lifecycle methods. When these methods are overridden, various lifecycle hook methods that do necessary work when the Activity changes states are also overridden, but this makes it easier to debug and monitor the application.
Lifecycle hook methods are a way to customize reasonable framework classes to run app-specific logic.
They are used because it is essential to know when an activity can be killed to avoid surprises, much like with animals, people, planets, etc.
The Android Manager Service has the job of calling the lifecycle hook methods back automatically and calling the lifecycle hook methods to Services and Broadcast Receivers, more on those later.
In any overridden hook method, the super class method is called first (super.methodName()) to see if the superclass has to do anything before we start doing something
If the hook method is not overwritten in the subclass, the Android Manager Service will invoke the default activity method implementations.
The activity lifecycle operations relate to the state that the activity can be in while executing.
Starting
Initialization stpes
Activity is launched on demand via an intent passed to startActivity()
Running
The activity is visible
It has the focus
It can do various computations to interact with the users
Paused
The activity is still visible
However, it loses focus to another activity
It is unable to perform computations to interact with the user because it does not have the focus
It can be Stopped then go back to Running or go back to Running right away
Stopped
The activity is not visible
It can be shut down or resumed at this state
It can also be involuntarily killed by the system
Destroyed
The activity is killed... for now. Or forever.
For more information, check out the Android Developement website created by Google!