Fixing activity lifecycle related bugs

This should fix some bugs related to the activity life-cycle.

They where reported at #416.