I solved this problem by wrapping the battery with a light band of tape -- like putting a belt around the battery's waist.
This kept the battery from shaking when I hit bumps ... problem solved.
Might not work for everyone, or every flashlight, but it worked for me, in two different flashlights.