Well it's either your battery or there is an open from your battery. Most times it's the battery. If you get a new battery and it does the same thing, then there is disconnect to your battery.
As far as the prolonging battery life, well it depends on the manufacturer. Some manufacturers say keep it plugged in while others say don't. Regardless, when the laptop is plugged in, it's running of AC power and not running on battery. And nowadays, you can't overcharge the battery. Technology has come so far to include a cutoff when the battery is fully charged. What I think that causes batteries to go bad while plugged in is that when a laptop is plugged in, your laptop computing processes run at a higher rate which generates more heat. And heat is a big external factor for causing batteries to lose it's charge capacity.