Time variability of active galactic nuclei and heating of cooling flows