Understanding Android Activity: Role, Lifecycle, Process States, and Additional Considerations
This article explains the fundamental role of Android Activity as the primary UI component, its interaction with layouts and context, how it saves state, handles configuration changes, switches with services, and details its complete, visible, and foreground lifecycles as well as the various process priority levels in Android.
Android Activity is the core interactive component that connects an app with the user, displaying UI layouts via setContentView() , receiving user commands, and presenting backend results such as notifications.
It provides a Context object, similar to Application and Service , enabling access to system resources throughout the app’s process.
Activities can persist transient data to restore the UI when the user returns, which is crucial when the system kills the process (e.g., when switching to another app).
When device configuration changes (e.g., orientation), Android recreates the Activity to reload appropriate resources, leveraging the state‑saving mechanisms.
Activities can start other Activities or Services via Intent , passing small amounts of data; they are managed in a stack where the topmost Activity is visible, and pressing the BACK key pops the stack.
The Activity lifecycle is illustrated with three overlapping phases:
Full lifecycle : from onCreate() (initialization) to onDestroy() (final cleanup).
Visible lifecycle : when the Activity is visible but may not receive input, transitioning through onStart() , onStop() , and onRestart() .
Foreground lifecycle : when the Activity is at the front and interacts with the user, involving onResume() and onPause() .
Android classifies app processes by priority, which is closely tied to Activity states:
Foreground process : actively interacting with the user (e.g., running Activity).
Visible process : visible but not receiving input (e.g., paused Activity).
Background process : not visible and without a running service.
Empty process : only retains cached objects after the app’s lifecycle ends.
Additional topics such as Activity stack management and the relationship with Intent are mentioned for future articles, and developers are reminded to register each Activity in AndroidManifest.xml before use.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.