added savePreferences function onPause()