Languages are complex systems that convey large amounts of information that do not appear on the surface.

What is the difference in English, for instances, between: "Have you seen that film?" and "Did you see that film?"

The difference, on the surface, is between two tenses of the past. But my informants tell me that the first sentence implies that it is still possible to see the film, that it is still playing in town. The second implies that the film is no longer availabe. These tenses contain linguistic markers that convey different meanings.

Have you ever thought about it when you asked or were asked this very question?

This premise is to introduce the difference between Passato Prossimo and Imperfetto.
The PASSATO PROSSIMO contains linguistic markers that indicate that an action BEGAN, TOOK PLACE and ENDED. That is an "event". Speakers of Italian, when they either speak or listen, hear those underlying messages.

The IMPERFETTO, on the other hand, does not explicitly say that an action either started or ended. It focuses only on the unfolding, on the "state" rather than the event.

Because the Imperfetto describes a state, it is most commonly used with verbs that are about "state" rather than "event." ESSERE and AVERE are two of such verbs: IO ERO simpy indicates the state of a person ("IO"), and doens't tell that the state ever ended. We may assume it did, but the verb doesn't way it.

However, even ESSERE can be used with the PASSATO PROSSIMO, to emphasize the fact that there was an end to that state: "IO SONO STATO IN ITALIA PER TRE MESI". This sentence requires the PASSATO PROSSIMO because it must convey the information that the state is over.

Usually, whenever information about lenght of time is present, the tense of choice must be Passato Prossimo.