How to Manage Android Application Life Cycle

Android application life cycle does not completely control its application lifecycle, It has its own Linux process. Android device has limited memory so this process is created for the application when a code is needed. Another component (Activity, Services, and BroadCastReceiver) in the application run and kill as needed for the application. That’s how the Android system manages the Android Application life cycle by reclaiming memory.

Manage Android Application Life Cycle new

Android system has priority for processes to ensure smoother and faster user experience by killing or terminating other processes when low memory.

These process types and its priority are :

1.  Foreground process :

This process is the highest processes. In Foreground process, the user is currently doing or interacting with application components. It’s defined in the following conditions :

  • If Activity is in front of user and user interacting with it. That time Activity is in onResume() state in Activity life cycle.
  • BroadCastReceiver is currently running.
  • Service is executing its one of callback methods:Service.onCreate(), Service.onStart(), or Service.onDestroy()

This processes will kill by Android system last, its very rare chance to kill this process because few only few processes are running in the Foreground.

2. Visible process :

In the Visible process, Activity is Visible in screen but in onPasue() state of Activity life cycle. Such a case dialog in front of Activity. So this Process will kill only when Foreground process is required to keep running.

3. Service process :

Which Service has been started by startService() method and doing like playing music, Downloading/Uploading data etc work? That process is not in front of the user but its really required for the user. So In low memory Android system will recover memory or resource only when Foreground and Visible process have not enough memory.

4. Background process :

If Activity is in,onStop() that time user not interacting with the activity. So, In this case, the Android system will kill the process as per the higher priority of the process. That type of many processes is running in case of system manage LRU and kill processes accordingly (LRU: Least Recently Used).

5. Empty process :

Empty process is doesn’t hold any active application components. Its only for improve startup time the next time a component of its application needs to run.

If you have knowledge about iPhone app development then you can compare the android Application life cycle with it. Where iOS app development controls all application’s life cycle from one place. In android its depend on the Android system, Activity Lifecycle, Services, Broadcast, etc.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.