I am new to coding and I was wondering, if there is a way to check when app loses focus(goes from foreground to background).

Is there anything like `onLosefocuslistener`?

To clarify I don't want when activity loses focus. I want when the whole app goes in background either cause user pressed the 'home' button or another app went in foreground.