On commercial flights do the pilots ever turn off the APU? Is it needed when flying?
This varies due to operational need and airline standard operating procedures.
On my aircraft (an Embraer E-Jet) we turn on the APU roughly ten minutes prior to pushback and shut it down shortly after starting the engines.
If we plan on taxiing on one engine we will shut it down after the first engine start and perform a cross-bleed start on the second engine. Other operators leave the APU running for second engine start.
If performance requirements demand the engine bleed to be off for takeoff we will leave the APU on until after takeoff to provide cabin pressurization until the engine bleeds come back online.
We typically leave the APU off for the remainder of the flight and do not turn it back on until the next flight, unless ground power is unavailable or unreliable at the destination, in which case we will turn it on after landing as we approach the gate.
The APU can also be left on (or started in flight) to assist with various abnormal or emergency situations where bleed air or electrical power generation might be needed. Each APU installation will have a different flight envelope in which it can be started / used and is specified in the aircraft's operational limitations.