Using magnetic activity and Galactic dynamics to constrain the ages of M dwarfs