Android process death — and the (big) implications for your app

Daniel Novak
Nov 14, 2016 · 4 min read
Image for post
Image for post

How to test the application background kill & restore?

  1. Launch your application, open some new Activity, do some work.
  2. Hit the Home button (application will be in the background, in stopped state).
  3. Kill the Application — easiest way is to just click the red “stop” button in Android Studio.
  4. Return back to your application (launch from Recent apps).
  5. Crash? You are doing something wrong in your application :-).
Image for post
Image for post
The easiest way to “kill” your application while in background
Image for post
Image for post
Set the background process limit to zero

Troublemakers in your app

  • Singletons
  • Any other shared instances that keep mutable data (such as injected dependencies where you keep some state)
  • Data and State stored in your Application class
  • Mutable static fields
  • Retained fragments (state is restored, data is lost)
  • Basically anything which is not stored in onSaveInstanceState and you depend on it

Know the Android platform rules

Any architecture, framework or library has to play according to the Android platform rules. So anytime you see a new library or approach — think about if and how is it handling state restoration.

INLOOPX

People at INLOOPX writing about anything.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store