Stellar Mass Function of Active and Quiescent Galaxies via the Continuity Equation