Explain the lifecycle of an activity or view controller and how you manage state transitions during configuration changes.