If you’ve ever accidentally pocket-dialled someone or accidentally clicked through things on your phone while it’s in your pocket, apps such as ‘Pocket Screen Lock’, ‘Pocket Mode’ and ‘Pocket Sensor’ can prevent this from happening.
These kinds of apps include a proximity sensor to enable them to detect when the phone is in your pocket whereupon it is locked and is unlocked again when it’s taken out of your pocket.
To find these and similar apps for Android, go to Google Play Store.