In case that you are using a free app, the app will shutdown after some time and then it needs to be restarted. You cannot prevent this in a free app.
As far as I know, this is handled by the mobile OS itself. Recent versions of Android have become very aggressive in closing background apps, in order to save battery. I am not sure of the specifics on iOS, but there is a setting in newer versions of Android, that allows you to specify apps which should not be optimized for battery life, which lets them stay open longer in the background. You can find it under Settings -> Battery -> Battery optimization -> (select your app) -> Don't optimize