Sometimes switching a game on and off will solve the problem, depending on how serious/ what the glitch is, but for the most part you'll need to restart your entire game (e.g. if you get a bad egg; AR codes will cause this and many other problems in your game).
Best way to prevent all of this? Don't cheat.