Android usually kills background processes if they do not have a persistent notification. Why do apps like whatsapp and Facebook not get killed?
Android usually kills background processes if they do not have a persistent notification.
Well most often this is the case, but Android OutOfMemory Killer (the component within Android responsible for killing processes) uses fairly complex logic and criterion to kill apps and processes which host these apps.
In Android, every application runs in a Linux Process. Each Linux Process has a Virtual Machine (Dalvik Virtual Machine or ART Virtual machine) running inside it. There is a limit on the memory a process can demand and it is different for different devices and also differs for phones and tablets.
When Android is running short on Memory space (may be because so many apps are simultaneously running in a device) OutOfMemory killer comes into picture and start killing processes of Apps which are in background first.
Now, apps such as WhatsApp, Facebook uses something called Service and Push notification mechanisms. Service allows app to run some code run in background and even though if App is Killed by OOM Killer, Service can be restarted again by Android when sufficient memory is available to make it run.
Why do apps like whatsapp and Facebook not get killed?
This is not true as Android can kill apps based on their state (such as foreground or background). It is just that the Apps and their component(such as Service) are being restarted as when they receive Push notifications, so that user can interact with the app.
So, as and when Push notification is received (means WhatsApp message), Android can restart the killed app's component(in this case WhatsApp).
This way Android is hiding the complex details of Memory management and process management from user and making sure that user can interact with an app without any issue.