This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 45702 - Disabling back press on modal page causes app to crash
Summary: Disabling back press on modal page causes app to crash
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.3.3
Hardware: PC Windows
: High major
Target Milestone: 15.5
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-10-19 16:58 UTC by James Mundy
Modified: 2017-08-14 14:42 UTC (History)
16 users (show)

See Also:
Tags: android, ac, modal
Is this bug a regression?: ---
Last known good build:


Attachments
This reproduce the same exception. (70.38 KB, application/x-zip-compressed)
2016-11-29 20:50 UTC, Christer Olsson
Details
This is a sample app to demonstrate exception when changing main page (70.96 KB, application/x-zip-compressed)
2017-06-13 15:45 UTC, tchadwick
Details

Description James Mundy 2016-10-19 16:58:29 UTC
I currently have an app with a MasterDetailView where the app's content is displayed. 

When the user is not logged in I overlay this page with a modal login page. I want to stop the user dismissing this modal view and seeing parts of the app they shouldn't underneath so I disable the back button press like so:

protected override bool OnBackButtonPressed()
{
    return false;
}

This works fine and if the user clicks back then the application exits as it should but this always causes a crash:

10-19 17:45:18.487 I/MonoDroid(22370): System.ArgumentException: Handle must be valid.
10-19 17:45:18.487 I/MonoDroid(22370): Parameter name: instance
10-19 17:45:18.487 I/MonoDroid(22370):   at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00017] in /Users/builder/data/lanes/3511/0e59c362/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12069 
10-19 17:45:18.487 I/MonoDroid(22370):   at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (System.IntPtr jobject, System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/data/lanes/3511/0e59c362/source/monodroid/src/Mono.Android/JNIEnv.g.cs:444 
10-19 17:45:18.487 I/MonoDroid(22370):   at Android.Support.V4.Widget.DrawerLayout.RemoveDrawerListener (Android.Support.V4.Widget.DrawerLayout+IDrawerListener listener) [0x00091] in <27c17fe440cf491ba8255bcefade6e02>:0 
10-19 17:45:18.487 I/MonoDroid(22370):   at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.Dispose (System.Boolean disposing) [0x001b6] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:172 
10-19 17:45:18.487 I/MonoDroid(22370):   at Java.Lang.Object.Dispose () [0x00000] in /Users/builder/data/lanes/3511/0e59c362/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:203 
10-19 17:45:18.487 I/MonoDroid(22370):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x0003f] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:226 
10-19 17:45:18.487 I/MonoDroid(22370):   at Xamarin.Forms.Platform.Android.AppCompat.Platform.Dispose () [0x00010] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:52 
10-19 17:45:18.487 I/MonoDroid(22370):   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnDestroy () [0x0002f] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:217 
10-19 17:45:18.487 I/MonoDroid(22370):   at Android.App.Activity.n_OnDestroy (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/data/lanes/3511/0e59c362/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.App.Activity.cs:2981 
10-19 17:45:18.487 I/MonoDroid(22370):   at (wrapper dynamic-method) System.Object:f9a47165-d328-4bd4-a949-71553b0bbab6 (intptr,intptr)
10-19 17:45:18.527 W/art     (22370): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
10-19 17:45:18.527 D/Mono    (22370): DllImport searching in: '__Internal' ('(null)').
10-19 17:45:18.527 D/Mono    (22370): Searching for 'java_interop_jnienv_throw'.
10-19 17:45:18.527 D/Mono    (22370): Probing 'java_interop_jnienv_throw'.
10-19 17:45:18.527 D/Mono    (22370): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.

It's not huge but something is definitely going on here.
Comment 1 softsan 2016-10-19 19:58:19 UTC
i am in the same boat:

System.ArgumentExceptionHandle must be valid. Parameter name: instance
Raw
  at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0000d] in <a39841fc98c24571bb4e438db328c33f>:0 
  at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <b202a60746f74f839a977b777275591c>:0 
  at Android.Support.V4.Widget.SwipeRefreshLayout.set_Refreshing (System.Boolean value) [0x00060] in <27c17fe440cf491ba8255bcefade6e02>:0 
  at Xamarin.Forms.Platform.Android.ListViewRenderer.<UpdateIsRefreshing>b__24_0 () [0x00000] in <95895bcb439e42ebb8e7134a545f1acc>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in <b202a60746f74f839a977b777275591c>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <b202a60746f74f839a977b777275591c>:0 
  at (wrapper dynamic-method) System.Object:5bced492-50ed-4186-8c36-acf16e27edc9 (intptr,intptr)
Comment 2 Chama 2016-10-20 11:44:24 UTC
Same bug here: When I replace the MainPage(LoginPage) by a MasterDetailPage(RootPage)
Comment 3 alperen babagil 2016-11-16 08:52:04 UTC
-
Chama 2016-10-20 11:44:24 UTC

Same bug here: When I replace the MainPage(LoginPage) by a MasterDetailPage(RootPage)
-

Same here. Any solution ?
Comment 4 adrianknight89 2016-11-20 20:29:00 UTC
I'm confused. It seems like some people are pushing a modal on top of a MDP while others are re-setting MainPage. Can you please attach a repro with your issues?
Comment 5 Christer Olsson 2016-11-29 20:50:25 UTC
Created attachment 18708 [details]
This reproduce the same exception.

Hi, I get the same exception when starting this small (minimal) application and then press the hardware back button. Happens every time!
Comment 6 adrianknight89 2016-11-30 00:39:07 UTC
See https://github.com/xamarin/Xamarin.Forms/pull/577
Comment 7 Samantha Houts 2017-01-03 19:23:01 UTC
Should be fixed in 2.3.4-pre2. Thank you!
Comment 8 Parmendra Kumar 2017-02-06 14:43:58 UTC
I have checked this issue with Xamarin.Forms 2.3.4.192-pre2 and observed that this issue has been fixed.

Hence closing this issue.


Thanks.
Comment 9 tchadwick 2017-06-09 17:23:07 UTC
I would like to see this reopened as the bug is back.  I have checked and it appears to have resurfaced as of 2.3.4.231 (2.3.4.224 does not have this issue)  Now I might also be experiencing a slightly different bug in that I'm changing from a NavigationPage(MasterDetailPage) as the MainPage to a NavigationPage(ContentPage), but it seems pretty much identical.  Also I have verified that the issue occurs in the latest pre-release build. (2.3.5.239-pre3)

Exception:
System.ArgumentExceptionHandle must be valid. Parameter name: instance
Raw
  at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0000d] in <a39841fc98c24571bb4e438db328c33f>:0 
  at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <b202a60746f74f839a977b777275591c>:0 
  at Android.Support.V4.Widget.SwipeRefreshLayout.set_Refreshing (System.Boolean value) [0x00060] in <27c17fe440cf491ba8255bcefade6e02>:0 
  at Xamarin.Forms.Platform.Android.ListViewRenderer.<UpdateIsRefreshing>b__24_0 () [0x00000] in <95895bcb439e42ebb8e7134a545f1acc>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in <b202a60746f74f839a977b777275591c>:0 
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <b202a60746f74f839a977b777275591c>:0 
  at (wrapper dynamic-method) System.Object:5bced492-50ed-4186-8c36-acf16e27edc9 (intptr,intptr)
Comment 10 tchadwick 2017-06-09 17:29:42 UTC
Quick change to previous comment, It is broken in 2.3.4.224 as well.
Comment 11 Samantha Houts 2017-06-12 16:06:42 UTC
Reopened as requested in Comment 9. Are you able to provide a small project that reproduces the issue you are experiencing?

Thank you!
Comment 12 tchadwick 2017-06-13 15:45:08 UTC
Created attachment 22860 [details]
This is a sample app to demonstrate exception when changing main page
Comment 13 Chris 2017-08-14 14:42:44 UTC
Hi,

I'm facing the same issue again. Was actually fixed in one of the previous versions.
Stacktrace:
Xamarin caused by: android.runtime.JavaProxyThrowable: System.ArgumentException: Handle must be valid.
Parameter name: instance
Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(JniObjectReference instance, JniMethodInfo method, JniArgumentValue* args)<301da1f2d2704e88be442c2c321fca07>:0
Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject, IntPtr jmethod, JValue* parms)<cf56e43a0e3d4f2f8785d2cba32db8aa>:0
Android.Support.V4.Widget.SwipeRefreshLayout.set_Refreshing(bool value)<27c17fe440cf491ba8255bcefade6e02>:0
Xamarin.Forms.Platform.Android.ListViewRenderer.<UpdateIsRefreshing>b__25_0()<1481f85a917c4f2b882ea161e9bc082f>:0
Java.Lang.Thread.RunnableImplementor.Run()<cf56e43a0e3d4f2f8785d2cba32db8aa>:0
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)<cf56e43a0e3d4f2f8785d2cba32db8aa>:0
at (wrapper dynamic-method) System.Object:65df57c8-a001-4441-a393-1f7ea70ce72c (intptr,intptr)
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:30
android.os.Handler.handleCallback()Handler.java:739
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:145
android.app.ActivityThread.main()ActivityThread.java:6117
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke()Method.java:372
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1399
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1194


For me it happens when I'm reopening the app via push notification after it was closed. 

Is there any solution?

Note You need to log in before you can comment on or make changes to this bug.