Game Development Reference
In-Depth Information
2.4 Main Activity
The main activity is presented to the user when launching the application for the first time. It
manages the overall lifecycle of the game, including initializing activities, switching content
or views, handling touch & keyboard events, registering listeners, binding to services, etc.
Managing the Activity Lifecycle
According to the Android Developer Forums [4] , an activity can be in different states which
are described by table 2.1:
State
Description
Running
The activity is in the foreground of the screen and interacts with the user.
This state is also referred to as "resumed".
Paused
Another activity is visible on top of this one and that activity is partially
transparent or doesn't cover the entire screen. It is completely alive but
can be killed by the system in extremely low memory situations.
Stopped
The activity is now in the background and can be still alive. However, it
is no longer visible to the user and it can be killed by the system when
memory is needed elsewhere.
Killed
Apps with higher priority need memory, so the activity is now dropped
from memory by finish() or killProcess() method. When it is displayed
again to the user, it must be completely restarted and restored to its pre-
vious state.
Table 2.1 Activity State
The Android system defines a lifecycle for activities via the following predefined methods
(table 2.2):
Method
Killable
Description
onCreate()
No
Called then the activity is created. Used to initialize the
activity - create views, bind data, and so on.
onResume()
No
Called just before the activity starts interacting with the
user. At this point the activity is at the top of the activity
stack, with user input going to it.
Search WWH ::




Custom Search