1

Inspired by the answer here (which has less votes than the top, but the comments seem to think is the most right) I've tried to create a mapFragment into my own fragment, which uses a LinearLayout as the container:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapFragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" />

My code to use this container to add both fragments is mostly the same:

protected override int FragmentId => Resource.Layout.FragmentXmlName;

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    FragmentManager fm = ChildFragmentManager;
    if (_mapFragment == null)
    {
        _mapFragment = MapFragment.NewInstance();
        FragmentTransaction ft = fm.BeginTransaction();
        ft.Add(Resource.Id.mapFragmentContainer, _mapFragment, "mapFragment");
        ft.Commit();
        fm.ExecutePendingTransactions();
    }

    return view;
}

The fragment is able to load a couple of times (I'm using MVVMCross's ShowViewModel). I load up the fragment with different parameters for the map this way. But eventually I get the error in the title, "Cannot Access A Disposed Object."

Have I missed something simple here of have I implemented this wrong?

Community
  • 1
  • 1
Chucky
  • 1,701
  • 7
  • 28
  • 62

0 Answers0