In order to prevent that, Replay Gain can be used. With this function the MP3 player uses loudness information in the header of a MP3 file to adjust the volume automatically.
However, the loudness information is not present by default. You need software to analyse the content and store those values in the MP3 header. Replay Gain does not change the underlying (music) data, thus avoiding loss in quality by decoding, processing and re-encoding.
A popular utility in the Linux world to calculate these values and tagging the file is mp3gain.
I used it regularly, but I was still adjusting the volume on my Sansa Clip+ ...
What I didn't know was, that by default mp3gain stores the information in the APEv2 tag which the Sansa Clip does not read. In order to be used by the Sansa Clip's Replay Gain function, it must be stored in the ID3v2 tag.
mp3gain has an option to do exactly that: -s i
I'm now using the following command to analyse and tag my MP3 files:
mp3gain -p -s i *
Where the option -p also preserves the original file date.