Acoustic Echo Cancellation (AEC)

You make a phone call or a conversation via intercom - and you hear yourself with a slight delay from the loudspeaker. The echo makes communication increasingly difficult or the conversation sometimes gets stuck. How can this problem be solved?