Fixed a bug where onPause would not be handekled correctly.