For mountain biking, in addition to thorns etc, you can also pinch flat - which is basically smacking something so hard it allows the tube to get pinched in between the rim and the tire.

Slime is supposed to be very useful in areas with lots of goat head thorns. I don't use it myself.

Another way to get flats is if your tire is old and stretched out a bit. I had one bike where the tire would shift ever so slightly on the rim, tearing the stem out. I had to get about a dozen flats like this before I figured out I needed to replace the tire and not the tube.

When I've flatted, I've always known right away.