In order to receive notifications about nearby Pokemon and have steps tracked for egg counting, you must have the screen on and the app in the foreground. You may use Battery Saver Mode to darken your screen and avoid looking at your phone. When the phone is turned upside-down (in your pocket, for example), the screen will darken but the app will continue running in the foreground.