Note: This applies to Android devices only and is not seen on Apple iOS devices.
Many Android device manufacturers employ aggressive power management policies that kill apps, even if they are legitimately running in the background (i.e. if your phone has the screen locked), usually to make the battery last longer between charges in these devices.
Google themselves have identified this as problematic behaviour by many manufacturers and have addressed this in Android 11.
If you experience this behaviour we highly recommend that you visit https://dontkillmyapp.com and look up the instructions for your device based on the manufacturer (i.e. Samsung).
If your manufacturer is not listed or you cannot find the appropriate settings then some general instructions are listed below (full credit: https://dontkillmyapp.com)
Always check the following setting Phone settings > Battery & power saving > Battery usage > Ignore optimizations > Turn on to ignore battery optimization for your app.
Check if Phone settings > Apps & Notifications > Your app > Background restrictions or Background limits are not enabled for the app.