Like the title says, what exactly happens when android runs low on memory? Does it randomly pick and choose activities and just kill them off or does it kill off entire back stack of an app.
I am worried that the history of my activities in my app will not be preserved properly (e.g. profile page coming before edit picture page)
It kills the whole process and not just some activities. Your app will be killed as a whole, if OS decides to kill the process in which your app in running.
If you go through Processes and Application Lifecycle
In most cases, every Android application runs in its own Linux process. This process is created for the application when some of its code needs to be run, and will remain running until it is no longer needed and the system needs to reclaim its memory for use by other applications.
Also if you go through Processes and Threads
By default, all components of the same application run in the same process and most applications should not change this. ... Android might decide to shut down a process at some point, when memory is low and required by other processes that are more immediately serving the user.
Hope it helps.