The best way to avoid problems with fruit flies is to eliminate sources of attraction. Produce which has ripened should be eaten, discarded or refrigerated. Cracked or damaged portions of fruits and vegetables should be cut away and discarded in the event that eggs or larvae are present in the wounded area. A single rotting potato or onion forgotten at the back of a closet, or fruit juice spillage under a refrigerator can breed thousands of fruit flies. So can a recycling bin stored in the basement which is never emptied or cleaned.
People who can their own fruits and vegetables, or make wine, cider or beer should ensure that the containers are well sealed; otherwise, fruit flies will lay their eggs under the lid and the tiny larvae will enter the container upon hatching. Windows and doors should be equipped with tight-fitting (16 mesh) screens to help prevent adult fruit flies from entering from outdoors
nice