The following is a very simplified explanation of the preterit and imperfect tenses in Spanish. I always think of the imperfect as an ongoing horizontal line with the preterit occurring at one particular point on that line.
Example: Comía cuando él me gritó. I was eating when he yelled at me. Eating is an ongoing activity or background against which the completed action of yelling occurs.
⇓
–––––––––––––—————————— ⇐ I was eating - Comía (The horizontal line)
⇑
When he yelled at me
Cuando él me gritó.
(The vertical arrows
show where the yelling
occurred in relationship
to eating).
As a general rule, the imperfect indicates an ongoing action, while the preterit has a beginning, a middle, and an end.
The imperfect can also be used for habitual actions, time or age in the past, to describe a condition in the past, or to describe an action that occurred during an unspecified time in the past.