How does an aircraft recharge its batteries? I assume aircraft have batteries that power up all electronic devices on board. But how are these batteries recharged? When the aircraft is on the ground, it can be connected and recharged in the airport, but mid flight? Is there a way to charge the batteries in the air ?

Next question, bit trickier: how many devices must be plugged by the passengers (via USB) and how long it takes to drain all energy on board of a 787 ?
The engines turn generators which supply the electrical power to the aircraft, including a battery charger that keeps the battery at 100%.  (Normally, power coming "from the battery" on the diagrams, is actually coming from the battery charger or another component like a Transformer-Rectifier converting AC to DC current.  The battery is very rarely actually being drained in flight.)

If you had an aircraft battery &amp; went to deplete it with USB devices, it would take a lot of them &amp; a really long time.  Aircraft batteries store power way beyond what our normal cell phones &amp; iPads do, and can power all the emergency systems on the jet for an hour or more (radios, INS, flight instruments, minimal lights, GPS, flight management system, etc).  Of course, if you're down to just the battery, in-flight entertainment is NOT one of the systems being powered!