In this work we study the permanence and extinction of a regime-switching predator-prey model with the Beddington--DeAngelis functional response. The switching process is used to describe the random changes of corresponding parameters such as birth and death rates of a species in different environments. When a prey will die out in some fixed environments and will not in others, our criteria can justify whether it dies out in a random switching environment. Our criteria are rather sharp, and they cover the known on-off type results on permanence of predator-prey models without switching. Our method relies on the recent study of ergodicity of regime-switching diffusion processes.