How do I code OnPause() and OnResume() for an Android.Support.V4.App.Fragment

I am using Xamarin and am coding a Google Maps application using fragments to use with a ViewPager. I have some working code for my application before using fragments, and the current code that I am working on.

I am extending the Google Maps using Android.Support.V4.App.Fragment

Here is my code before adding fragments:

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        MapsInitializer.Initialize(this.ApplicationContext);
        SetContentView(Resource.Layout.MapWithOverlayLayout);

        InitMapFragment();
        SetupMapIfNeeded();
    }

    protected override void OnPause()
    {
        base.OnPause();
        _map.MyLocationEnabled = false;

        _map.InfoWindowClick -= HandleInfoWindowClick;
        _map.MarkerClick -= HandleMarkerClick;
    }

    protected override void OnResume()
    {
        base.OnResume();
        SetupMapIfNeeded();

        _map.MyLocationEnabled = true;

        _map.InfoWindowClick += HandleInfoWindowClick;
        _map.MarkerClick += HandleMarkerClick;
    }

Here is the code that I am working on:

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        rootView = inflater.Inflate(Resource.Layout.MapWithOverlayLayout, container,false);
        MapsInitializer.Initialize();

        InitMapFragment();
        SetupMapIfNeeded();

        return rootView;
    }

    protected override void OnPause()
    {
        base.OnPause();
        _map.MyLocationEnabled = false;

        _map.InfoWindowClick -= HandleInfoWindowClick;
        _map.MarkerClick -= HandleMarkerClick;
    }

    protected override void OnResume()
    {
        base.OnResume();
        SetupMapIfNeeded();

        _map.MyLocationEnabled = true;

        _map.InfoWindowClick += HandleInfoWindowClick;
        _map.MarkerClick += HandleMarkerClick;
    }

Here are the errors that I am getting:

Error CS0507: 'SimpleMapDemo.MapWithMarkersActivity.OnPause()': cannot change access modifiers when overriding 'public' inherited member 'Android.Support.V4.App.Fragment.OnPause()'

Error CS0507: 'SimpleMapDemo.MapWithMarkersActivity.OnResume()': cannot change access modifiers when overriding 'public' inherited member 'Android.Support.V4.App.Fragment.OnResume()'

Can I please have some help to get this code working?

Thanks in advance

Best Answer

Answers

  • Thanks.

Sign In or Register to comment.