|
Pro Android with Kotlin@de android telegram Pro Android with Kotlin Developing Modern Mobile23
CHAPTER 3: Activities
Paused
: The activity loses focus but is still at least partly visible. Losing
the focus, for example, happens when the user taps the Back or
Recents button. The activity may continue to send updates to the UI
or continue to produce sound, but in the majority of cases the activity
will proceed to the stopped state. During the pausing, the
onPause()
callback gets called. The paused state is followed by the stopped state
or the resumed state.
Stopped
: The activity is invisible to the user. It later might be restarted,
destroyed, and expunged from the active process list. During stopping,
the
onStop()
callback gets called. After stopping, either destruction
or starting happens. Here you can, for example, stop the service you
started in
onStart()
.
Destroyed
: The activity is removed. The callback
onDestroy()
gets
called, and you should implement it and do everything there to release
resources and do other cleanup actions.
Table
3-1
lists the possible transitions between an activity’s states, which are illustrated in
Figure
3-1
.
Table 3-1.
Activity State Transitions
From
To
Description
Implement
Shut Down
Created
An activity gets called the first time or
after a destruction.
onCreate()
: Call
super.onCreate()
,
prepare the UI, start services.
Created
Started
An activity starts after creation.
onStart()
: You can start services
here that are needed only while the
activity is visible.
Started
Resumed
The resumed state automatically
follows a started state.
Use
onResume
.
Resumed
Running
The running state automatically
follows a resumed state.
The activity’s functioning including
UI activity happens here.
Running
Paused
The activity loses focus because the
user tapped the Back or Recents button.
Use
onPause
.
Paused
Resumed
The activity has not stopped yet,
and the user navigates back to the
activity.
Use
onResume()
.
Paused
Stopped
The activity is invisible to the user, for
example, because another activity
gets started.
onStop()
: You can stop services
here that are needed only while the
activity is visible.
Stopped
Started
A stopped activity gets started again.
onStart()
: You can start services
here that are needed only while the
activity is visible.
Stopped
Destroyed A stopped activity gets removed.
onDestroy()
: Release all resources,
do a cleanup, and stop services
that were started in
onCreate
.
|
|
|