Whenever my kids have acted up in public, I give them one fair warning including what I call the "ear boxing"...which is where you firmly pull their ear slightly downward while talking firm in their ear. It gets the point across and it stings, but doesnt do any real harm. I let them know they do it again, and we stop whatever we are doing and leave. And I have left restaurants, stores, and other errands.
Also, I have also started walking away from them should they start a tantrum. It always works because a) they aren't getting the attention they need and are desperately looking for and b) they don't like the sensation of mommy walking away.
I let my kids know that whenever my kids acted up, they lost privileges like TV, the park, coloring, anything that was important to them, including sleeping toys for night time or the night light. All these things have allowed them to understand I do not put up with tantrums and that their actions have consequences.
So when you are in public, don't take the time to acknowledge the problem in the bathroom; half of the embarrassment for the child is that I would deal with them in front of the audience they created. Also, if you walk them to the bathroom, you are allowing the child to take control because they know that they have a means to interupt you and what you are doing to "deal with them"...at that point, negative attention is better than no attention, in the eyes of a child.
Last, at home, when your child acts up, firmly state if they do it again, they will sit in time out. You start time out for the length of their age, so if hes 2, 2 minutes. But you do not start the time out until he starts acting the way you want in the corner. If he starts yelling, let him know that you will start counting again once he is acting the way you want him to. If it takes 30 minutes, then so be it...but while you are doing that, go back to you meal and ignore him. Do not talk to him otherwise outside of the fact that he is getting too noisy. Let him know that he will come back to his meal only if he sits quietly in his time out, and once he has successfully done that, have him apologize to you and whomever else for his behavior. Once he has done that, let him go back to his dinner or whatever activity.
Do not worry about associating one activity to another...he needs to know that his actions warrant consequences outside of the activity at hand. As for outtings with friends, let him know you want him to go if he's a big boy who can behave, otherwise he won't get to go...which means you will have to do it on your own time. But stay strong and let your friends know up front, if he acts up and doesn't start behaving, I will have to cut my part of the dinner short. The friends will understand and be grateful you aren't allowing your child to make a scene. It is why I make sure I always had my car in the beginning in case I had to do this.
I will say this, due to the time out, taking away items, and the ear boxing, I don't have any problems in public and at home I don't get too many problems either. My kids are well behaved and I don't have to worry about being embarrassed every time I go out to run errands or enjoy an outting. My kids want to be part of the errands and outtings and understand Mom means business...i have no qualms embarrassing them back and getting up and leaving and later taking away privileges.
Just stand firm and don't relent...your child will behave the way you want with minimal frustration on your part.