Implemented the saveInstanceState to save state in lifecycle changes.