Setting up code to handle OnPause/OnResume events properly.