Fixed enableForegroundDispatch bug by ensuring application is active.

Small fix to prevent Exception on application exit.