I wish I could say there is one sure- fire, practical way.
(technically there is - simply do not ever bring fruit or anything that has come in contact with their larvae into your home and you are golden, but lets be honest we all love a good banana in the morning or summer watermelon)
I have divided the course of action against fruit flies into two categories: avoidance (you do not currently have fruit flies in your living space), and extermination (you need to get rid of them)
Here are some helpful hints to avoid appearance of fruit flies.
1) Store all fruit in the refrigerator
2) Empty trash often, and keep the container clean
3) Keep your sink and counter tops clean and dry
Extermination:
1) ATTACK THE SOURCE.
it is crucial that you ask yourself the question- where are these dudes congregating.
It may be your sink, trashcan, wet dishcloth- anything. First deep- clean and dry the source and then all affected areas immediately affected to more distant.
Added emphasis on keeping this immediately affected space CLEAN and DRY.
Do not leave food out.
2) MAINTAIN THE CLEAN SOURCE. repeat all above steps constantly.
3) KILL OFF THE CURRENT FLIES
Why are Drosophila melanogaster a model organism in genetics? Because of their rapid breeding capabilities.
It is important to not just expect the flies to go away- they can live up to ten days and continue to mate and lay eggs. They pose a constant threat to multiply and overcome your space and you must treat the flies as such a threat - do not take this lightly once you have cleaned the space.
The greatest difficulty I find is in STEP 3 of Extermination. How to kill the flies?
To a mere amateur they may actually believe that swatting their hands at and aimlessly clapping midair will rid themselves of the flies. FALSE. While having 20-20 vision helps, you need to follow some basic steps to kill the individual flies
1) emphasis on INDIVIDUAL flies. take it one at a time. they are quick and have very good sight capabilities to see all around them (email me if you would like pictures of their compound eyes and ocelli)
2) move quick
3) decide to kill while they are either STATIONARY or MID-FLIGHT. Here my murder methods move into two categories.
STATIONARY:
Use a small, but heavy book to smash the fly. Start close to the surface moving slowly at first then swat fast and hard.
*the palm of your hand or a equally uneven surface will simply not do the trick. you must use a flat surface and move quickly.
MID-FLIGHT
Use either 409, or all purpose cleaner to spray or the hand clap method.
*Beginners, I recommend using the 409 method. Without bleach- you don't want stains in carpet, walls etc. The clean up is a nuisance, but it is the easiest way.
*For those who are more experienced, flatten hands and clap fast repeatedly around the fly. Do not stop following the fly with your eyes and clapping your hands until you are sure you clapped it to death. It is easy to be fooled because of the flies small body size and quick evasive flight movements.The downside to this method is some may find the dead fly on their hand slightly disgusting. So make sure a sink and or purell (by the way studies show purell is much more effective in total amount of bacteria killed, so I recommend purell) nearby.
Happy fly hunting!