For distance to register, you need to have the app open and running. If you minimise it or lock your phone or anything, the distance you walk will not count. There is a "Battery Saver" mode that will black out the screen but keep the app active which does record distance correctly and saves battery.
Their is a max speed where if you travel faster then that, any distance travelled will not count. For instance, being on a train with the app open will only record the slow parts of the trip (arriving and leaving a train station). The fast parts dont count.
Some goes with driving obviously, I've been told the speed limit is 60kmph, but i've only tested myself at 20kmph which works fine. So doing a lap of your local gyms, late at night, doing 20kmph, will count as walking. I'll try confirm the max speed at some point. I tried 40kmph and it didnt register - so the max speed is between 20kmph and 40kmph.
Just so its clear, yes the app needs to be running an open for any walking distance to count. Riding too fast on a bike can also cause distance not to count. Best to check your phone after travelling for a bit to see if the distance is being recorded and adjust accordingly.