Here is an extension to get the activity lifecycle state of an app. So e.g. whether an app is switched in the background and / or in idle (sleep) mode.
According to my experience and tests, however,
onStop is always triggered after
The following have been tested: alarm, incoming phone call, idle mode, split screens, ...
Maybe someone will find a scenario where this doesn't happen.
Or maybe @ewpatton can explain, when this might happen.
See also here (video): https://community.kodular.io/t/taifun-tools-activity-changed/69554/12?u=bodymindpower