This uses the existing android lifecycle methods to avoid having to do null checks and state saving in various places.