Extracted the logic for converting an activity to a continuation.