In phones with Android 6 or later which feature Doze mode and App standby, battery optimization in apps takes place when your phone is in a deep sleep state or when apps haven't been used for days. This helps to extend battery standby time.
If you need to keep certain apps active even when you're not using them, you can turn off battery optimization in these apps. This keeps them running in the background, but may cause them to use more battery power.
See the user guide or how-tos to find out how to turn off battery optimization in an app.