Implemented onPause() to save data.