Mealiness mostly happens to old apples that have been kept in storage, or in improper storage, for too long. Buying apples as close as possible to when they were picked is the surest way to avoid getting mealy ones. If you're buying out of season, try tapping the side of the apple: good ones will sound hollow while mealy ones will sound dense and dull.
If you do wind up with a bag of mealy apples, you can still use them in cooking! Cooking helps to break down the cells themselves, releasing the liquid inside. Try using them to make baked apples with oatmeal and brown sugar, a topping for pork chops, or just cook them down into applesauce.
Do you have any tricks for identifying a mealy apple?
Related: Pick Your Own Apples: For Suckers?