Seems like there's a lot of guessing going on here and no definitive answers. My Nexus 7 2012 used to charge just fine whether powered on or off. And it used to stay at 100% as long as it was plugged in. A few months ago after one of the Android 4 updates, everything changed. Now it will not charge or stay charged while powered on. It will only show a charging icon and charge when powered off, and then only if I disconnect and reconnect the USB/charge cable. About 3-4 days ago it got the Lollipop 5.0.2 update. The problem is not cured. I'm using the original AC adapter and cable. My guess is that it's a software bug that was introduced during the later Android 4 updates and has still not been fixed as of Android 5.0.2.
I have the Battery app by Macropinch installed. It has separate icons for battery, AC plugged in, USB connected, and WiFi on. The Nexus 7 is plugged in to the original adapter and cable, powered up and the Battery app running, but the AC plug icon is not lit. There is no lightning bolt on the battery icon in the notification bar at top of the screen. The battery is 90% charged and the estimated time left is 4 hrs and 30 min. I started with a fully charged battery when I began this post. It looks like there is rapid battery drain going on, too, and I have no other apps running.
I power the device down. Screen is dark. It won't start charging until I disconnect the USB/power cable and then reconnect it, then a large white battery icon with lightning bolt displays for a few seconds, then another battery icon with the current charge level shown as a vertical bar graph inside the battery icon, then the screen goes dark. Now if I bump the power button for a half second it repeats the display sequence just described. But if I just power down the device, wait for it to be dark screen for a minute, then bump the power button it boots up instead of displaying the charging icon sequence. Because it ain't charging. Sure would like to know what's going on.