As a Sun-like star is born from a collapsed nebula and generates energy by nuclear fusion some of that energy is converted to magnetic fields which fuel solar activity. How does that activity evolve as the star itself evolves?
As in the Earth and more than in the the giant gaseous planets the Sun's magnetic field is generated like in a dynamo. A few facts about it:
- The rotating plasma inside the Sun acts like a dynamo creating it's magnetic field.
- The plasma is ionized so all interact with the magnetic field and vice-versa.
- The sun as a fluid body also has Differential rotation, that means the equatorial part of it rotates faster than the poles. This provokes what is known as the Solar cycle every 11 years.
At the begining of the Solar cycle the Sun's magnetic field is pointed North-South as in the Earth. During the cycle the differential rotation makes the plasma interact with the magnetic field causing it to be displaced. This makes the first the Sun's spots appear near the poles. As the cycle advances the magnetic field get more and more scrambled, it's orientation changes to west-east and the spots appear closet to the equator. Finally the magnetic field can't hold the "pressure" and "breaks" like a rubber band creating the biggest spots and flares. The magnetic field stabilizes again but with a south-north polarity and the cycles begins again.
Take a look at this gif image that shows how the cycle go.
And in this image you can see what is know as the butterfly diagram that shows how the Sun's spots are located closer to the equator as the cycle advances. And it lasts 11 years.
Magnetic activity depends on rotation due to the dynamo mechanism. Younger stars in general rotate faster. They (stars like the sun) spin down because their ionised winds interact with their magnetic fields and gradually remove angular momentum. A star like the Sun at 100 million years old may have had a rotation period of 0.5-5 days - much faster than the present-day Sun.
Roughly speaking, magnetic activity scales with the square of angular velocity, so young stars can be orders of magnitude more active than the Sun, manifested as much stronger coronal X-ray emission, flares and much greater coverage of starspots and strong magnetic fields.
Conversely, stars older than the Sun should be a bit less active, although the rate of spindown slows with rotation rate and so the changes beyond a few billion years are not so great and not so well calibrated.
A useful review article would be Ribas et al. (2005)