For an application that has multiple UIAbility components, the application is in the background only when all of its UIAbility components are in the background.
You can use the ApplicationContext.on('abilityLifecycle') API. The first parameter of this API is of the abilityLifecycle type, which indicates the lifecycle of UIAbility components in the application. The second parameter is a callback function, which can be used to listen for the switchover between the foreground and background.