Handle onPause and onResume.