I am seeing inconsistent documentation and discussion regarding what happens when Android is low on memory and the steps the OS takes to re-claim memory. More specifically, does Android kill at the granularity of activity/fragment, or entire process?
For example, if Activity B is launched in front of Activity A (and both activities are part of the same app/process), can Activity A be killed by the OS while Activity B is in the foreground and the user is interacting with Activity B (assume: screen remains on, current app remains in the foreground, no orientation change occurs)?
This SO answer from 2011 (by Dianne Hackborn on the Android team at Google) suggests that Android kills at the granularity of a process, NOT an activity.
On the Android Developer pages on Recreating an Activity, it says:
The system may also destroy your activity if it's currently stopped and hasn't been used in a long time or the foreground activity requires more resources so the system must shut down background processes to recover memory.
Notice the ambiguity: "the system must shut down background PROCESSES".
On the Android Developer pages for onSaveInstanceState, it says:
For example, if activity B is launched in front of activity A, and at some point activity A is killed to reclaim resources, activity A will have a chance to save the current state of its user interface via this method
After reading through these and many other doc pages and online discussion, it is not clear what the correct answer is.
I also have the same question regarding fragments: Can a backgrounded fragment be killed due to low memory, without its entire process being killed?