Knowing when to use the preterite or imperfect tense when expressing a past action is one of the trickiest aspects of spanish grammar and can cause confusion for any level of spanish speaker. I always like to remind myself of the distinction between the two, followed by regular practice of using them.
Preterite Tense
The preterite tense expresses actions that took place and were completed at some point in the past. It is useful to remember that it may be accompanied by time phrases such as: ayer (yesterday), hace una semana (a week ago)...
e.g Trabajé en un banco. I worked in a bank. (A completed past event).
Imperfect Tense
The imperfect tense refers to an ongoing state or action in the past, whose beginning or end is not specificed. A useful reminder is in that the word 'imperfect' itself suggests the idea of being 'incomplete'.
e.g Trabajaba en un banco. I used to/was working in a bank. (An ongoing past action).
Using both tenses
When we use both tenses in one sentence it is useful to remember that the imperfect is used to describe what was going on and when this action is interrupted, we use the preterite tense.
e.g Mientras estudiaba en mi habitación, mi hermano entró. (While I was studying in my room, my brother entered).