As mentioned note taking to help you remember where you left off.
However, I am going to treat your question more along the lines of how can I manage interuptions....
Ask the question: Can it wait until I have completed X? (or at least until you can stop at a point that works well for you).
Size up the issue that is possibly causing the context switch. If the issue is large, compare it to what you are doing and see if you can complete what you are doing to devote your attention to the other.
See if you can schedule the interuption. A little like the first two except that those are trying to stop the immediate interuption and make it a little more orderly. In this case, you are trying to see if the interuption is really that important and/or gauge just how important it is. For example, you could say, well I am really trying to complete X. Can I get to this first thing tomorrow?
Reduce your distractions as much as possible. Can you turn off your IM, email, etc... perhaps these are causing some of the switching.
Plan your day as best possible armed with "What do I need to accomplish today?" you might be able to fend of some of the interuptions by simply stating your goals.
If it's really bad, talk to your manager and try to reach either an understanding (if they are part of the problem) or see if he/she can help you in this situation. Discuss how the context switching is very inefficient and is slowing you down. Perhaps a process can be created / followed that will better manage the interuptions.
I'll add this link to Joel Spolsky on Developer's getting in the "zone" or flow. It's huge and I have found it to be very true indeed. http://www.joelonsoftware.com/articles/fog0000000068.html
Goes along with Kristo's article's also on the topic...