onPause and onResume functionality added