The lights, bells and gates are activated by a short circuit between the rails of the track. The short being the wheels of the train (or someone laying a bed spring across the rails).
But, in reality, it is a bit more complicated than that. It is not just a relay that is closed when current flows between the rails.
There is usually a short across the rails some distance from the crossing anyway, so current is always flowing, but because of the distance and the resistance of the metal, the current flow is low.
As a train crosses over that short and gets closer to the crossing, the current flow goes up as the short circuit caused by the train makes the distance shorter as the train moves. The control circuitry in the small house/box next to the crossing is measuring the current, but not just how much is flowing, it is also measuring how fast it is changing.
The change in current flow, combined with the total current flow, is what triggers the crossing lights (etc.). This way, if a train is traveling slow, the trigger doesn't occur until the current flow is high (based on total current flow) and if the train is traveling fast, the trigger occurs sooner (based on rate of change)... both ways the time between the trigger and the train arriving at the crossing is about the same. I think the FRA mandates at least 20 seconds, and most RR's set it to closer to 30.
I think the voltage (causing the current flow) is around 24 or 48 volts, not enough to shock you or an animal that happens to touch both rails at the same time... and the current flow is limited such that a light bulb would not illuminate if you connected it across the rails.
Because the voltage is so relatively low and the current is so limited, and the circuit is so sensitive, any change in moisture will sometimes affect the trigger. Rain, relative humidity, temperature (or even an animal relieving itself near the rails) can change the current flow just enough to make the circuit trigger the lights (etc.)
There are adjustments built-into the circuitry to vary the trigger point, both for total current and rate of change. The signal maintainer probably just opened the door to the control box and barely jiggled one of the knobs to get the system to reset. He does NOT want to go making large changes to the settings as that might shorten the trigger time to below the FRA mandate.
If major work is done to a crossing (or near it) the signal maintainer will have to get in his rail truck and drive through the crossing (with the rail to rail short on the truck enabled) at a fixed speed to test that the circuit trigger is set to the proper time.