If the phone shut off while showing some battery left and then at zero the next time you got the screen on, then it's most likely the battery going bad.
You don't really have to worry much about how to charge, though. Charging during use doesn't hurt anything other than to make it charge slower, or in extreme use cases, possibly lose charge (I.e. Running GPS, gaming, and downloading a large file all simultaneously). If you're having issues charging it, the most common culprit is the cable went bad. Micro-USB cables are weak in my opinion because they often break their internal connections right behind the micro plug housing. If this is your issue, I've had the best luck with the Volutz brand. A bad USB port can cause the same symptoms and there's some checks you can make to verify one or the other, but isn't as often the problem.