I had this happen when a drunken mate tried to climb into the front of the car before I had come to a full stop, taking the mirror off with his head.I tried many things, but hot days would often cause it to fall off.
I think it is Loctite that make a kit that includes a mesh and gue rather than a sticky pad. I cleaned off all the old reminants first with very fine grit sandpaper then a good wipe down with alcohol to clean it thoroughly The mesh goes in between the mirror and the glass, and takes up the slight surface difference between the flat mirror pad and slightly curved window. Get yourself in a position where you can prop your arm up for a long time (15 minutes) and stick it on, keeping firm pressure and as still as possible. After fixing, try not to drive for several hours to give the glue time to cure fully. Actually though, that statement is redundant since your arm will ache too much to drive anyway. This has stayed stuck for years.