While there are specific times to use both, I find that imperfect is used when there is no definite stopping place or if the action is a continuing thing in the past. While the preterit is a one time action- starts, stops.
Cuando hablaba, me estornudó.
When I was walking (it's just a continuing action in the past), I sneezed (happened and ended).
Cuando era un niño, mi mamá murió.
When I was a kid, my mom died.
Being a kid is the underlying action, 'died' is the singular action that began and ended. hope this helps :)