BackgroundTask.beforeExit and App.exitApp()

How should I close or minimize App during BackgroundTask.beforeExit is running? If I just call App.exitApp code in BackgroundTask.beforeExit will not be completed

In general you should never need to run exitApp because the user should have full control over the lifecycle of your app.

However, the way to use beforeExit is to make sure you call it if you are still running a long-running task and the app will be suspended: https://capacitorjs.com/docs/apis/background-task#example