Update code to prevent app crash from rotation