Fix data race issue
Only unset the state-changed handler if the current handler is what we (the task management activity/service) previously set.
Otherwise, it means that somebody has taken over message handling so the field should not be changed!