protected override void Dispose(bool disposing) { if (fragment != null) { RemoveMapEvents(); if (fragment.StateSaved) { var activity = (AppCompatActivity)Context; var fm = activity.SupportFragmentManager; fm.BeginTransaction() .Remove(fragment) .Commit(); } fragment.Dispose(); fragment = null; } base.Dispose(disposing); }
protected override void OnElementChanged( ElementChangedEventArgs <MapView> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.TakeSnapshot -= TakeMapSnapshot; e.OldElement.GetFeaturesAroundPoint -= GetFeaturesAroundPoint; } if (e.NewElement == null) { return; } if (Control == null) { var activity = (AppCompatActivity)Context; var view = new Android.Widget.FrameLayout(activity) { Id = GenerateViewId() }; SetNativeControl(view); fragment = new MapViewFragment(); activity.SupportFragmentManager.BeginTransaction() .Replace(view.Id, fragment) .Commit(); fragment.GetMapAsync(this); currentCamera = new Position(); } }