Oggyo The only way to really prevent an app from running in the background is to disable the app when you're not using it and enabling it again when you want to use it. Unfortunately, this can become tedious. On other non-GOS devices, I used various app managers that required root access to manage disabled apps. One of them I used was Disabler on F-Droid.
The other way is to force Doze to run sooner. I have tried two apps that do this. One is Naptime and the other is Comatose. To use, you will need to issue an ADB command to allow Naptime and Comatose to do their thing. You should only use one of these apps though and not at the same time. I use Comatose on GOS with the extreme profile setting due to its simplicity. You can find out more about Comatose's profiles here. I know GOS generally prefers not to issue ADB commands to apps, but I do so because I'm a power user.