How Many States Does an Activity Have?
The Activity lifecycle section in the Application Fundamentals tutorial states that there are 3 states:
An activity has essentially three states:
(1. active/running 2. paused 3. stopped)
But then as I continued reading the actual Activity class documentation, the Activity Lifecycle section states that there are 4 state:
An activity has essentially four states:
(1. active/running 2. paused 3. stopped 4. "dropped"?)
Both sources (on the same website) agree about the first 3, but the 4th one is only mentioned in the class documentation and is unnamed.
So, are there really 4 states or only 3?
If there are 4, what is the name of the 4th one?
Please help me understand this discrepancy.
I would describe it as three states. The fourth "state" is non-existence, in that Android may destroy the activity to free up RAM. However, if that activity is still reachable via the BACK button, Android will hang onto the Bundle from onSaveInstanceState() and use that when it recreates the activity. If you wish to consider this cached Bundle a "state", I wouldn't quibble, but it's not the way I usually describe it.
Also, highlighted colored blocks in this beautiful and very informative flowchart don't seem to correspond to the states.
Mostly, that diagram is showing the sequence of the lifecycle methods. As you say, it is a flowchart, more so than a state diagram.
Where, in the flowchart, would you mark the 3 or 4 states?
I wouldn't. However, the active/running state is the green "activity is running" bubble, the paused state is the white "The activity is no longer visible" bubble, and the stopped state would be in between onStop() and onDestroy(). The non-existence "state" would be the red "Process is killed" bubble.
This diagram depicts 4 states, the 4th being labeled Destroyed.
However, as you can see, this 4th "state" leads nowhere. That is, unlike the 3 other states which are "leave-able" to another state, this "Destroyed" state is a dead end.