Fix crash bug if the app is in background