I was leaving when he arrived . ( means I had already decided to leave and in the process of leaving when he got in)
I left when he arrived. ( meas I was not in the process of leaving and my leaving happened after he had arrived)
I think you can figure out the difference in the two examples , each of which can be an answer to your questions.