Android Lollipop has a battery-saver mode that you can switch on to save precious power when your battery gets low. Android M builds off of Lollipop with an enhanced “doze” mode , which limits certain background tasks when your phone’s been inactive for a period of time.
If you want all background tasks to continue for a given app, though, you can turn “doze” mode off on a per-app basis. Go to Settings > Battery, then go to the Options menu (the three dots in the upper right) and ta Ignore optimizations. Tap the downward-pointing arrow, then tap All apps. Tap an app’s name, then toggle the Ignore optimizations slider to the on position.