[General] Move the end flag to the event passed to onDeactivate and onFinalize
#3887
+33
−189
onDeactivate and onFinalize
#3887