How does solar activity (e.g. flares, coronal mass ejections) change over the life cycle of a Sun-like star? 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.