Most of the times reason behind this is Android OS killing app when in background, and special optimisations made by miui/samsung/vivo are to be blamed.
However you can whitelist app which hopefully Android OS will respect. The shortcut way to do is to be enable whitelist mode in-app preferences first option.