Use this expression when someone has misunderstood what you wanted to say. You should especially say this when you say something in a friendly, innocent way, but someone gets offended by it. Here's another example:
B: Oh, thanks a lot! (Sarcastically)
A: No, I didn't mean it that way. I meant that you sound like you have a cold or something.
The phrases "I didn't mean it that way" and "I didn't mean it like that" are pretty much the same.