In Spanish, both pretérito perfecto simple (canté) and pretérito imperfecto (cantaba) have dozens of uses. The main difference is that pretérito simple shows an event as finished, and imperfecto doesn’t.
This means that if you want to show an action as occuring while something else was happening, or that it was interrupted by another action, or with habitual actions (which originally don’t have a finish), imperfecto is used instead.
Consider these examples:
(Ex.1) Ayer escribí 2 páginas. (≈Yesterday, I wrote 2 pages.)
The pages were completed: finished action.
(Ex.2) Ayer estuve escribiendo un ensayo. (≈Yesterday, I was writing an essay.)
The essay wasn’t completed (written in its entirety), but the action of writing is seen as finished. This might be a bit unintuitive, since we are using both pretérito—that deals with finished actions—and progressive structure. In this case, it roughly means I was writing, but keeping the action seen as finished. Notice that saying escribí would mean that the essay was completed; while saying estaba escribiendo or escribía would require more context (compare with the example (4) and its description below).
(Ex.3) Ayer escribí/estuve escribiendo el ensayo 20 minutos. (≈I wrote for 20 minutes.)
Same as (2): 20 minutes is seen as a period that passed, and the action seen as finished, but the essay hasn’t been completed. (You’d say “escribí […] en 20 minutos” to mean ‘in/under 20 minutes.’ Such an action would be seen as completed, so it would not be compatible with estuve escribiendo—which is seen as finished, but without reaching the goal that is writing the entire essay.)
(Ex.4) Ayer escribía/estaba escribiendo un ensayo. (≈Yesterday, I was writing an essay.)
This is unfinished and you’re expected to continue your story example my pen broke/I had to go to the store/I started thinking about… Basically it sounds as if you set up a time frame and were going to say more.
(Ex.5) Escribía/estaba escribiendo cuando me llamaste. (≈I was writing when you called me.)
Just like (4), in this case writing is seen as interrupted by the call.
(Ex.6) Cuando estaba en la uni, escribía más a mano. (≈When I was in university, I used to write by hand more.)
When I was in uni (setting up time frame) + I used to write more by hand (seen as a habitual action which doesn’t have a clear end). This can also be seen as two simultaneous events.
Read more on pretérito vs. imperfecto with the espanolavanzado links below. I highly recommend you read them, especially the first two articles—even a few times—in order to understand everything.