Hi,
I am getting below exception when I try to open Android Activity from Forms page.
System.NullReferenceException: Object reference not set to an instance of an object
at at Xamarin.Forms.Platform.Android.AndroidActivity.OnPrepareOptionsMenu (Android.Views.IMenu) <IL 0x00007, 0x00050>
at App.Forms.AndroidUI.SyncStatusActivity.OnPrepareOptionsMenu (Android.Views.IMenu) [0x00001] in d:\App.Xamarin\App.Forms.Android\SyncStatusActivity.cs:152
at Android.App.Activity.n_OnPrepareOptionsMenu_Landroid_view_Menu_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.App.Activity.cs:3326
at at (wrapper dynamic-method) object.1a5b215d-fa89-44d4-97fd-9092c10808c9 (intptr,intptr,intptr) <IL 0x00017, 0x0004b>
Let me explain this in detail. I opened Activity A from Xamarin.Forms page. Activity A is derived from AndroidActivity Class. Above exception was due to some problem with below code.
public override bool OnPrepareOptionsMenu (IMenu menu)
{
//Exception at this point
return base.OnPrepareOptionsMenu (menu);
}
I added above code in my Activity A, because I saw somewhat similar post related to this issue.
comment from there
Try to override OnPrepareOptionsMenu method and do nothing if you started another activity
I don't face any issue, If I derive Activity A from Activity Class. This problem has started after deriving Activity A from AndroidActivity. Since I need to open Forms page onclick of button from Activity A, I derived it from AndroidActivity. What's wrong here?
How to fix it?