Make sure the app optimization/power saver/battery saver is turned off on your phone for that particular app. If it's not set to off or 'not optimized', then the phone will close the background apps.
Battery optimization
To keep your apps working properly make sure you enable:
Settings -> Apps -> Your App -> Battery -> Battery optimization -> All apps -> Your app -> Don’t optimize.
You can find how to do that here depending on the device manufacturer:
https://dontkillmyapp.com