Fix activity state handling