In what conditions is the APU used in midair?
This answer applies to the AVRO RJ (BAe 146), because this is the aircraft I've flown. Other aircraft may or may not have similar features/issues/restrictions.
Reasons for APU use in mid-air

For takeoff, the APU bleed-air can be used to supply the cabin air pressure system to reduce load on engines. This leads to a significant reduction in runway length required. This is routinely used on short runways.
Similar reason for the landing, where, for the missed approach/go-around phase, a high climb gradient is required. For example in mountainous areas or combined with icing conditions, where use of engine bleed air is limited, the APU bleed air can feed the cabin pressurization.
During flight, when in icing conditions. Similar reason as above. The air-frame anti icing system uses that much bleed-air, there is not much left for cabin pressurization (or the other way round). If the APU bleed-air is used to pressurize the cabin, the (already low) climb gradient is improved.
During flight, in the event of a generator failure. The generator of the APU can replace one failed generator of an engine.
To save engine life. If APU bleed air (- to pressurize cabin) is used for normal takeoff, the peak engine temperatures will be lower during takeoff. This increases engine life as the peak engine temperature is the main factor of engine life. It's significantly cheaper to replace an APU than an engine.

In all of the above cases, there are restrictions on the operation of the APU. It may not light-up above 15'000 ft or operation above 25'000 ft is not allowed or not recommended. General operating rules for the APU (common sense when using turbines) recommend to use bleed air only after couple of minutes warm-up after startup. Likewise, on shutdown, it should be left running without load to cool down for a few minutes before switching off. The exact timings differ greatly between APU models.
Procedures

Before Takeoff, If the APU is not used during climb, the APU is normally shut down during taxi checks. If the pilots decide to use the APU during climb, it is started during normal engine start. In this case the APU bleed air is used to feed the cabin pressurization.
After Takeoff depending on the model of the APU (and following airline procedures), the APU usage is limited to a specified time or altitude. Before reaching this limit, the APU has to be shut down. (cabin air changeover to the engine bleed air, cool-off period of the APU, switching off)
During Flight In case of a technical problem or emergency, the Abnormal Checklist will suggest or dictate the use of the APU for the remainder of the flight. For example: A generator problem, the APU generator replace the failed generator. This may impose limits to flight altitude and duration.
Before Landing Usually after passing 10'000 feet, the APU is started and before the final checks, the cabin pressurization system is switched to the APU.