Ohms law Volts = Current x Resistance. This also applies to Volt drop across a Resistance. If your starter motor draws 100 amps and you have a bad connection of only 0.1 ohm, then volt drop =100 x 0.1 which is 10 volts. As you only have 12 volts in a battery,loosing 10 volts only leaves 2 volts, not enough to hold the soleniod in. The 1st click is the solenoid going in, you drop 10 volts and the solenoid drops out (2nd click) you are no longer drawing any current so the voltage rises to 12 and pulls in the solenoid (3rd click) this causes the volt drop again and the solenoid drops out (4th click) and so on. If the battery is shot it doesn't need a bad joint to cause this, it just can't deliver enough current so its voltage drops across its internal resistance.