Hello there,
I will try to give an accurate explanation for the issue I'm facing.
Context :
I'm using a MasterDetailPage for my main navigation. In a Detail page (used as a NavigationPage), I display a ListView of items. Each item can be deleted or edited through Context Actions.
The Edit Action:
I want to navigate to another page (the page which allows editing of the selected item) as a PushAsync navigation. I also tried to set a new Detail element to the RootView to navigate to my page.
Both methods are set up in the App class.
PushAsync :
public static void PushNav(Page target)
{
RootView.Navigation.PushAsync(new NavigationPage(target));
}
Detail navigation :
public static void NavigateToDetail(Page target)
{
var rootPage = (RootView)rootView;
rootPage.Detail = new NavigationPage(target);
}
I tried both Command method and .Clicked event, they are both throwing errors.
var editWeezo = new MenuItem
{
Text = AppResources.ContextActionEdit,
Command = new Command(() =>
{
//App.NavigateToDetail(new DetailWeezoView());
App.PushNav(new DetailWeezoView());
})
};
editWeezo.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
//editWeezo.Clicked += EditWeezo_Clicked;
The issue:
When I'm trying to navigate from the page after completing the context action the app crashes and it throws an unhandled exception :
PushAsync method :
08-20 11:22:19.435 I/MonoDroid(23204): UNHANDLED EXCEPTION:
08-20 11:22:19.437 I/MonoDroid(23204): System.InvalidOperationException: PushAsync is not supported globally on Android, please use a NavigationPage.
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.Platform.Android.Platform.PushAsync (Xamarin.Forms.Page,bool) <IL 0x0000a, 0x00064>
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.NavigationProxy.OnPushAsync (Xamarin.Forms.Page,bool) <IL 0x00025, 0x00173>
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.NavigationProxy.PushAsync (Xamarin.Forms.Page,bool) <IL 0x00016, 0x000d3>
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.NavigationProxy.OnPushAsync (Xamarin.Forms.Page,bool) <IL 0x00025, 0x00173>
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.NavigationProxy.PushAsync (Xamarin.Forms.Page,bool) <IL 0x00016, 0x000d3>
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.NavigationProxy.PushAsync (Xamarin.Forms.Page) <IL 0x00003, 0x0004f>
08-20 11:22:19.437 I/MonoDroid(23204): at WeezoApplication.App.PushNav (Xamarin.Forms.Page) [0x00001] in D :\TFS\Weezo\WeezoApplication\WeezoApplication\WeezoApplication\App.cs:88
08-20 11:22:19.437 I/MonoDroid(23204): at WeezoApplication.View.ViewCell.ListWeezoViewCell/<>c.<.ctor>b__0_0 () [0x00001] in D :\TFS\Weezo\WeezoApplication\WeezoApplication\WeezoApplication\View\ViewCell\ListWeezoViewCell.cs:26
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.Command/<>c__DisplayClass4_0.<.ctor>b__0 (object) <IL 0x00006, 0x00057>
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.Command.Execute (object) <IL 0x00007, 0x0005b>
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.MenuItem.Activate () <IL 0x0001c, 0x000ff>
08-20 11:22:19.437 I/MonoDroid(23204): at Xamarin.Forms.Platform.Android.CellAdapter.OnActionItemClicked (Android.Views.ActionMode,Android.Views.IMenuItem) <IL 0x00018, 0x000f3>
08-20 11:22:19.437 I/MonoDroid(23204): at Android.Views.ActionMode/ICallbackInvoker.n_OnActionItemClicked_Landroid_view_ActionMode_Landroid_view_MenuItem_ (intptr,intptr,intptr,intptr) [0x00019] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.ActionMode.cs:89
08-20 11:22:19.437 I/MonoDroid(23204): at (wrapper dynamic-method) object.9ebb5098-b40b-4897-96f5-75a6a4246824 (intptr,intptr,intptr,intptr) <IL 0x0001d, 0x00053>
08-20 11:22:19.443 W/art (23204): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
08-20 11:22:19.445 D/AndroidRuntime(23204): Shutting down VM
An unhandled exception occured.
NavigateToDetail() method :
08-20 11:10:18.262 I/MonoDroid(22511): UNHANDLED EXCEPTION:
08-20 11:10:18.265 I/MonoDroid(22511): System.ArgumentException: 'jobject' must not be IntPtr.Zero.
08-20 11:10:18.265 I/MonoDroid(22511): Parameter name: jobject
08-20 11:10:18.265 I/MonoDroid(22511): at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr) [0x00010] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:546
08-20 11:10:18.265 I/MonoDroid(22511): at Android.Views.ActionModeInvoker.Finish () [0x0002d] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.ActionMode.cs:804
08-20 11:10:18.265 I/MonoDroid(22511): at Xamarin.Forms.Platform.Android.CellAdapter.OnActionItemClicked (Android.Views.ActionMode,Android.Views.IMenuItem) <IL 0x0001e, 0x00127>
08-20 11:10:18.265 I/MonoDroid(22511): at Android.Views.ActionMode/ICallbackInvoker.n_OnActionItemClicked_Landroid_view_ActionMode_Landroid_view_MenuItem_ (intptr,intptr,intptr,intptr) [0x00019] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.ActionMode.cs:89
08-20 11:10:18.265 I/MonoDroid(22511): at (wrapper dynamic-method) object.131b4de3-aed8-4d12-ac3c-68605ad2766e (intptr,intptr,intptr,intptr) <IL 0x0001d, 0x00053>
08-20 11:10:18.271 W/art (22511): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
08-20 11:10:18.273 D/AndroidRuntime(22511): Shutting down VM
An unhandled exception occured.
Cannot undertstand the "jobject" error.
Do you have any suggestion of how to navigate in this case of use ?