How to stop fruit flies & other winged menaces.
Don't leave food out & wash your dishes every night.
Clean your cat's litter box daily.
The end.
If you do end up with an infestation, apple cider vinegar traps work well, and can be even be made by a primitive.