Hi Hazel,
I am not sure exactly what causes this, but if I am understanding you correctly, I have had the same recurring problem. It seems almost as though something in the hip flexor is out of place and wants to "pop," even though there isn't any bone right there! Mind you I am not well-versed enough in physiology to give you a description of what it is, but I can tell you about my experience with this problem.
For starters, I find that it is mainly triggered by extreme movements. These can be kicks, lifts, or stretches of any magnitude that is outside of my usual range of motion. Activities such as running, flexibility training, or strength training seem to precede the onset of it. I find, in general, that while it is in pain, stretching or exercising that area seems to increase the problem. I assume that some gentle stretching would be fine, but I tend to kind of have a problem doing "gentle" stretches. I have found, however, that after a few days time, or a week, or however long it takes the majority of the discomfort to subside, that to do some moderate strength training does wonders to help protect this area. After mine started to feel better, I began to do some very slow, controlled circular motions with the widest possible range of motion with both my legs, in both clockwise and counter-clockwise directions, and from both standing (with a wall or char nearby for balance and stability) and lying positions. Weak hip flexor muscles will "feel the burn" pretty fast.
For the most part, now, I can split, V-lift, teddy bear, run, and do most other activities and movements that involve extreme contractions, elongations, and exertions from the musculature along the hip flexor without pain.
One very good stretch for the hip flexor is the warrior pose from Yoga. Another is as follows: if you wish to stretch your right hip flexor, enter a kneeling position by lunging forward with your left leg. Slightly arch your back, and slightly turn your right shoulder forward so that your left pivots back. For a slightly more challenging stretch, you may raise your right arm and lean over to your left side. I've heard Veena recommend using the Dove and Bow/Bridge poses for stretching the hip flexors.
But I would suggest doing only very light stretches, or no stretches at all, until the pain mostly goes away. And when you do begin stretching and exercising it, don't forget to have a good warm-up first. In my experience, rest has been of the greatest benefit for this problem. Ibuprofen and daily or twice-daily application of an ice pack may be helpful also if there is discomfort even when you are not exerting or stretching the muscle.