Sort out some activity lifecycle problems