How does an activity know about change in state?
When the user switches from one app to another app, the system calls onPause() lifecycle state on the running app, and onResume() lifecycle state on another app which is previously not in the active state. It switches between these two methods each time the user toggles between apps.