23 Aug 2012

Android Activity LifeCycle Part 2

In Android, the applications are run as a separate Linux process. So the application lifecycle is closely related to the process lifecycle. The application process lifecycle is handled by the system depending on the current system memory state.
In case of low memory, the Android system kills some less important process. The process importance is decided depending on the state of the process components.
The process types depending on the importance are as follows (from most important to least important):
1. Foreground process: A foreground process is the application process with which the user is currently interacting. The process is considered to be foreground if its Activity is at the top of the Activity stack (its onResume() has been called) or BroadcastReceiver is currently running (onReceive() method is currently getting executed) or its Service is executing callback functions like onCreate(), onStart() or onDestroy() methods.
2. Visible Process: A visible process is the process which has an Activity visible to the user (its onPause() method has been called).
3. Service Process: Service process contains a Service for which startService method is called and the service is running.
4. Background Process: The background process does not have any visible activities to the user. (Activity onStop() method has been called).
5. Empty Process: Empty process is the one that does not have any active application components. These processes are kept on for caching purpose.
It is important that application developers understand lifecycle of the application process. Not using these correctly can result in the system killing the application’s process while it is doing important work.
Read More !