A melody is comprised of notes, usually from a particular key. Those notes could and often do, add up to the scale of that key, when put in order, with root first.
Thus, in A, there'll be A,B,C#,D,E,F# and G#.So, a tune in A will use those notes in the main.Take any of those notes, and stack the next but one and the next but one to that, and maybe one more, per se. That gives the chords that work well with that key, basically.
Still using that same set of notes, but starting the 'scale' on the second note will give the Dorian mode. Stating on the 3rd, it'll be the Phrygian, etc. So, A Ionian will have exactly the same set of notes as B Dorian, as C# Phrygian, etc. How those notes are ordered to produce the melody will vary with the underlying chord - or vice versa. Modes are sort of based around whatever note they represent in a key, as in A major (Ionian), B Dorian has exactly the same notes, but centres around B, C# Phrygian same again, but C# centre, etc.
So, after all that, it seems you're asking 'should I use the same notes from the key of A, even when I'm on a new chord?' Well, yes, because you're in the same key. Whether its A major or E Mixolydian, it's the same set of notes.On an E chord, yes, use E Mixolydian, as they'll fit like the rest of the notes from A major, because they are the same notes.