The evolution of the star formation activity in galaxies and its dependence on environment