yeah, the andromeda and milky way galaxies will merge together in around 2.5 billion years.
it's really impossible to predict what effect that will have on the earth. the most likely scenario is that it will have no effect, that any other bodies will still remain quite far away from our solar system. another possibility that is very unlikely is that our sun will collide with another star forming a larger star and destroying most if not all the planets in our solar system. Another still more unlikely scenario is that a star smaller than our sun will enter the solar system at a point equidistant between the earth and the sun, and it will have no effect on the earth, but it will cause atmospheric changes in some of the farther rim planets.
either way in 5 billion years our sun will stop producing fusion and it will either engulf the earth or if not it will reduce in temperature enough to freeze the entire planet.
the most unlikely scenario of all, and our best hope is that a larger star orbits close enough to the earth to pull it into it's gravitational feild and into a new solar system. Of course the probability of the earth not getting destroyed or undergoing climate change enough to wipe out 99% or more of the population in any scenario is an absurdly high number.
I have a strong feeling that if the human race hasn't completely wiped itself out in the next million years or so, give or take, it will only be by virure that it has wiped itself out just enough to start the evolutionary process all over again.
All good things must come to an end eventually.