I have forms project where I use a custom ContentPage and a PageRenderer based on this code:
forums.xamarin.com/discussion/18014/mixing-forms-content-and-native-activity
I can navigate to my android activity with :
buttonB.Clicked += async (object sender, EventArgs e) =>
await Navigation.PushAsync(new MapPage());
but I cant figure out how to navigate back to the forms page, the back button does not do anything.
MapPage is simply and empty ContentPage.
My Renderer looks like this:
`
using System;
using Xamarin.Forms.Platform.Android;
using Android.Gms.Maps;
using Xamarin.Forms;
using Android.App;
using Android.Views;
using Android.Gms.Maps.Model;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.ComponentModel;
using Android.Graphics;
[assembly:ExportRenderer(typeof(FormsMaps.MapPage), typeof(FormsMaps.Droid.MapPageRenderer))]
namespace FormsMaps.Droid
{
public class MapPageRenderer : PageRenderer
{
Android.Views.View view;
private MapFragment _mapFragment;
private GoogleMap _map;
private bool _gettingMap;
private MapPage _mapPage;
private Activity _activity;
protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
{
base.OnElementChanged(e);
_mapPage = (MapPage)e.NewElement;
SetPage(_mapPage);
// load the axml file for this view
_activity= this.Context as Activity;
_activity.SetContentView(Resource.Layout.MapLayout);
view = _activity.LayoutInflater.Inflate(Resource.Layout.MapLayout, this, false);
AddView(view);
InitMapFragment();
SetupMapIfNeeded(); // It's not gauranteed that the map will be available at this point.
}
private void InitMapFragment()
{
_mapFragment = _activity.FragmentManager.FindFragmentByTag("map") as MapFragment;
if (_mapFragment == null)
{
GoogleMapOptions mapOptions = new GoogleMapOptions()
.InvokeMapType(GoogleMap.MapTypeTerrain)
.InvokeZoomControlsEnabled(true)
.InvokeCompassEnabled(true)
.InvokeRotateGesturesEnabled(true)
.InvokeScrollGesturesEnabled(true)
.InvokeTiltGesturesEnabled(true)
.InvokeZoomGesturesEnabled(true);
FragmentTransaction fragTx = _activity.FragmentManager.BeginTransaction();
_mapFragment = MapFragment.NewInstance(mapOptions);
fragTx.Add(Resource.Id.map, _mapFragment, "map");
fragTx.Commit();
Markers = new List<Marker>();
}
}
private void SetupMapIfNeeded()
{
if(null != _map || _gettingMap) return;
var mapReadyCallback = new MyOnMapReady();
mapReadyCallback.MapReady += (sender, args) =>
{
_map = mapReadyCallback.Map;
// set up annotations etc here
_gettingMap = false;
};
_gettingMap = true;
_mapFragment.GetMapAsync(mapReadyCallback);
}
}
}`
How can I navigate back?