When does the Town Shield kick in after an attack?
Solution 1:
The automatic shield is deployed when certain conditions are met:
When 40% of your village or your Town Hall is destroyed in a raid, you will get a 12-hour shield. When 90% or more buildings are destroyed you will get a 16-hour shield instead (these two shields cannot be stacked together).
For the most part, you'll see shields deployed when you lose a battle, as opposed to a successful defense. There are some corner cases (ie, Town Hall intact and 40-49% of the buildings destroyed) where you can both win and get a shield.
As far as I know, there's only one raid allowed on your town at a time. Thus, if you trigger an automatic shield as a result of a raid, you should be granted immediate protection against further raids.