Not sure if it's exactly what you're looking for, but greenify might do the trick. You might need root.
Also Android now has the doze feature that should hibernate apps by default when not used.
[0]https://play.google.com/store/apps/details?id=com.oasisfeng....