Note: before you begin, make sure you’ve read my previous post
about Binder tokens!
Since the very beginning, Android’s central focus has been the ability to multitask. In order to achieve it,
Android takes a unique approach by allowing multiple applications to run at the same time. Applications are
never explicitly closed by the user, but are instead left running at a low priority to be killed by the system
when memory is low. This ability to keep processes waiting in the background speeds up app-switching later
down the line.
Developers learn early on that the key to how Android handles applications in this way is that processes
aren’t shut down cleanly. Android doesn’t rely on applications being well-written and responsive to
polite requests to exit. Rather, it brutally force-kills them without warning, allowing the kernel to
immediately reclaim resources associated with the process. This helps prevent serious out of memory situations
and gives Android total control over misbehaving apps that are negatively impacting the system. For this reason,
there is no guarantee that any user-space code (such as an Activity’s onDestroy()
method) will
ever be executed when an application’s process goes away.