By practising good housekeeping, you can help prevent a Fruit Fly infestation.
Fruit Flies enjoy overwintering in garden debris. So by clearing this regularly, you'll make your garden a less attractive spot.
Try to pick fruits before they become too ripe and fall to the ground. If they do fall, be sure to pick them up.
Don't put decaying fruit in the compost bin. The Fruit Flies will be there in no time if you do! As well, try to keep the compost aerated, turning every few weeks. Always keep the compost covered with a lid.
Covering crops with a fine mesh can sometimes be an effective barrier against Fruit Flies.
Likewise, there are various traps that can be obtained on the internet or made at home. This can be highly beneficial to detect and monitor garden populations.