Created attachment 17191 [details]
Repro for Modal Issue
Receiving an exception when using PushModalAsync for a page wrapped in a NavigationPage on Android. This is occurring when navigating from a page containing a Google map.
The exception is: "Java.Lang.ClassCastException: android.widget.ImageView cannot be cast to android.view.ViewGroup"
I have seen two difference behaviours; 1) the exception is raised on PushModalAsync, 2) the modal appears with blank contents and the exception is raised on the second PushModalAsync.
Two reproductions have been created - one with a custom renderer and one with Xamarin Forms Maps (attached). The issue has been reproduced on Android 4.4, 5.1 and 6.
FormsAppCompatActivity is used.
Created attachment 17192 [details]
Repro for Modal issue (custom renderer)
I am getting the same error. Any progress on this?
*** Bug 42579 has been marked as a duplicate of this bug. ***
I'm having same error. Any workaround maybe?
Unhappy workaround I'm using: on the parent page, before calling PushModalAsync, I set mapContainer.Content = null; (mapContainer is the ContentView that encapsulates the map). When the modal is popped, I set mapContainer.Content = map. Unfortunately, this causes the map renderer to be disposed, so the map is reset. I store the map state separately.
Let me know if this works for you guys or if you were able to come up with something better.
I ended up creating a toolbar control (title, toolbar button etc) to mimic the NavigationPage toolbar and just not wrapping the page in a NavigationPage...
Also tried removing the map as you did but not convinced that this can be made stable in all scenarios.
Scott, I tried your workaroud and that is ok, the MyModalPage is not blank anymore.
But there is a problem: in my case, I'm pushing a NavigationPage(MyModalPage). Then, when I push any page on this NavigationPage and Pop it, I receive this same exception again.
Does anybody have another workaround for this?
Marlon and Scott, I have same problem, found a solution to solve the problem?
I have not found a solution for this issue. The workaround was to drop the use of NavigationPage with modal dialogs and use a custom toolbar.
Also, I haven't retested this on the latest pre-release so that might be worth trying.
My workaround for this is to also not use modal dialogs but instead of a custom toolbar, I use the NavigationPage and just hide the back button and block the hardware back button on Android.
Works very well and I don't need a custom toolbar.
I.e. NavigationPage.SetHasBackButton(this, false);
Cliff, what do you mean when you say "block the hardware button"?
I didn't know it's possible... can you post your code here?
Ohhh I just override the OnBackButtonPressed and it works! For some reason I thought it only works on ModalPage... so it's working here. I will try to avoid modal pages until Xamarin fix it.
I am also getting the same error.
Xamarin Forms 2.3.*
Xamarin team have't provided any solution so far... :(
Also getting the same error.
VS Debugger puts no XF frames on the stack. Passing the buck...
0xFFFFFFFFFFFFFFFF in System.Diagnostics.Debugger.Mono_UnhandledException_internal C#
0x1 in System.Diagnostics.Debugger.Mono_UnhandledException at /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/corlib/System.Diagnostics/Debugger.cs:122,4 C#
0x6 in Android.Runtime.UncaughtExceptionHandler.UncaughtException at /Users/builder/data/lanes/4468/b16fb820/source/xamarin-android/src/Mono.Android/Android.Runtime/UncaughtExceptionHandler.cs:43,4 C#
0x1C in Java.Lang.Thread.IUncaughtExceptionHandlerInvoker.n_UncaughtException_Ljava_lang_Thread_Ljava_lang_Throwable_ at /Users/builder/data/lanes/4468/b16fb820/source/monodroid/src/Mono.Android/platforms/android-25/src/generated/Java.Lang.Thread.cs:226,5 C#
0x1D in object.d6057ee3-d2dd-4858-b077-cc7759738351 C#
Same error here. The workaround of removing parents does not work all of the time. I still get the error. I think Android is trying to "catch up".