refs #1, save the application state when leaving the application.