Managing the activity lifecycle