.app-desktop{ --postPageVerticalPadding: 0px !important; }
top of page

When Android kills your app

Our phones are smart little devices that we rely on every day. They’re packed with a wide variety of apps, some are just for fun, some are useful for daily tasks like streaming videos, and others are critical for our security and well-being, such as banking apps. Whether you're a regular user or an Android developer, it's important to understand how the Android operating system behaves.



Smart Android


An Android device isn’t as powerful as it might seem to the average user. It has limited RAM, limited internal storage, and—most importantly—a limited battery. That’s why the creators of Android designed it as a multitasking operating system that manages apps dynamically. To maintain smooth performance, system stability, and battery efficiency, Android may terminate apps under certain conditions.


Applications in android are not ‘immortal’


When a user launches an application and then presses the Home button (the circle icon) to return to the main screen, whether to open another app or for any other reason, the first app moves into the onStop state. At this point, the app is no longer in the foreground but continues running in the background. If the user returns to it within a reasonable amount of time, the app typically resumes as if nothing happened. However, if Android needs to free up RAM, often because the user opens another app, the system may kill the background app to reclaim memory.


System-initiated process death


And this is exactly the case, background applications can be killed by the system. However, this isn't considered a crash. When the user returns to the app, it should ideally reopen on the same screen and restore its previous data. But behind the scenes, the entire application is being reloaded from scratch, which can take slightly longer than a normal background-to-foreground transition where the process remains alive.


Android system process death triggers and scenarios


Android may terminate app processes in certain situations to ensure system performance and stability. It's important to note that foreground apps (those currently visible to the user) have the highest priority and are the least likely to be killed.


  1. Low Ram


    • When the system runs low on memory, Android starts terminating background apps, and in rare cases, even foreground apps, to free up RAM.

    • The Least Recently Used (LRU) algorithm determines which apps are killed first.

    • Apps consuming more memory are more likely to be targeted.


  2. Battery optimization


    • To improve battery life, Android restricts background processes.

    • Apps running in the background without a foreground service may be killed after a few minutes, especially under Doze mode or app standby conditions.


  3. System-Level Policy & OEM Customizations


    • Some manufacturers (e.g., Xiaomi, Huawei, Samsung) have aggressive battery-saving policies that kill background apps.

    • Certain system events (e.g., app updates, crashes, security policies) can also trigger app termination.


User awareness


As a user of an Android application, system-initiated process death can negatively affect the overall experience. When returning to an app, the user may find that previously entered data, such as text typed into a form, has disappeared. In some cases, the app may reset entirely, returning to the main screen and causing the user to lose even more valuable information. From my perspective, users should avoid leaving an app in the background for an extended period if they are working with important or unsaved data.


Android developers awareness


As an Android developer, there are a few key things you should keep in mind. When working with ViewModels, you can use SavedStateHandle, which is provided through the ViewModel’s constructor. Under the hood, it's a simple key-value map that retains data even after a system-initiated process death. For data that needs to persist more reliably, such as user settings or app content, consider using SharedPreferences, DataStore, or Room.


Please remember that an Android application is not a singleton. Avoid storing mutable data, such as IDs or default values, as properties in repositories or other singleton-like components. These values can be unexpectedly overwritten or lost, especially after a system-initiated process death or app restart. Understanding how Android handles background apps is essential for delivering a smooth user experience. 


If you're an Android user, be aware that returning to an app and finding missing data isn’t just a glitch, it’s often a sign of poor app design. If you're an Android developer, it's crucial to understand the Android lifecycle and deeper system behaviors, like process death, to build more resilient and user-friendly applications.



Written by Peter Mikolajewicz, Sr. Mobile Developer at Bravo LT.










Comentários


Our Offices


40 Monroe Center NW, Suite 200
Grand Rapids, MI 49503

United States

Rio Mississippi 303 Ote, Col Del Valle
San Pedro Garza Garcia, NL 66220

Mexico

66 Szańcowa St.
01-458 Warsaw

Poland

Unit 1002, One Corporate Plaza

845 A. Arnaiz Avenue

Legazpi Village

Makati City 1229

Philippines

Mission

 

Our mission is to empower our clients, team, and community to succeed through compassion, professionalism, and the power of technology.

  • Instagram
  • Twitter
  • Facebook
  • LinkedIn
bottom of page