If you back up to iCloud (or iTunes on a computer) and restore a new iPhone from that backup, you'll get your iMessages back. If you move to Android or some other operating system, those iMessages are not recoverable on your new phone. They'll still be in that backup file though.