Bug 61044 - App crashes when return from background
Summary: App crashes when return from background
Status: NEEDINFO
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 7.0 (C8)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2017-12-08 11:13 UTC by Luan
Modified: 2017-12-08 17:43 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 61044 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEEDINFO

Description Luan 2017-12-08 11:13:16 UTC
I have this problem runnign Xamarin.Android which happens ocasionally. To simulate the problem, I open one activity inside my program and minimize it. Then, I open another app (like google maps, of Settings, for example). When I return, the program crashes showing "The App stopped". This is the logcat of the moment of the error:


Error	7776	AndroidRuntime	  at Java.Interop.TypeManager.n_Activate (System.IntPtr jnienv, System.IntPtr jclass, System.IntPtr typename_ptr, System.IntPtr signature_ptr, System.IntPtr jobject, System.IntPtr parameters_ptr) [0x00189] in <07cc2c8668cc4cf4b0b334d25424a46d>:0 
Error	7776	AndroidRuntime	  at Modelo.MD_Parametros.get_Perfil () [0x00008] in <cd67dccacaf74fda9b96645f718f622c>:0 
Error	7776	AndroidRuntime		at md5044160bdd3b04941689b7308e2483e28.AC_Pedido.<init>(AC_Pedido.java:32)
Error	7776	AndroidRuntime	  at (wrapper dynamic-method) System.Object:b86a0d8b-9e30-472a-9412-631ae5bf579c (intptr,intptr,intptr,intptr,intptr,intptr)
Error	7776	AndroidRuntime		at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
Error	7776	AndroidRuntime	  at Persistencia.ModelBase.Load () [0x00000] in <188c5af2ae56445c80c728e34f5d043d>:0 
Error	7776	AndroidRuntime		at java.lang.reflect.Method.invoke(Method.java:372)
Error	7776	AndroidRuntime		... 4 more
Error	7776	AndroidRuntime	java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
Error	7776	AndroidRuntime		at java.lang.reflect.Method.invoke(Native Method)
Error	7776	AndroidRuntime		at android.os.Looper.loop(Looper.java:135)
Error	7776	AndroidRuntime		at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Error	7776	AndroidRuntime	Caused by: android.runtime.JavaProxyThrowable: System.NotSupportedException: Could not activate JNI Handle 0xbebcbdc8 (key_handle 0x26df4146) of Java type 'md5044160bdd3b04941689b7308e2483e28/AC_Pedido' as managed type 'Visao.AC_Pedido'. ---> System.NullReferenceException: Object reference not set to an instance of an object
Error	7776	AndroidRuntime		at mono.android.TypeManager.Activate(TypeManager.java:7)
Error	7776	AndroidRuntime		at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
Error	7776	AndroidRuntime	  at Java.Interop.TypeManager.n_Activate (System.IntPtr jnienv, System.IntPtr jclass, System.IntPtr typename_ptr, System.IntPtr signature_ptr, System.IntPtr jobject, System.IntPtr parameters_ptr) [0x000fb] in <07cc2c8668cc4cf4b0b334d25424a46d>:0 
Error	7776	AndroidRuntime		at mono.android.TypeManager.n_activate(Native Method)
Error	7776	AndroidRuntime		at android.app.ActivityThread.access$800(ActivityThread.java:155)
Error	7776	AndroidRuntime		at android.app.ActivityThread.main(ActivityThread.java:5343)
Error	7776	AndroidRuntime		at android.os.Handler.dispatchMessage(Handler.java:102)
Error	7776	AndroidRuntime	  at (wrapper dynamic-method) System.Object:3baf69a6-fd8a-4e08-84e6-533dc4b76e25 (intptr,object[])
Error	7776	AndroidRuntime	  at Modelo.MDN_Perfil..ctor (System.String codigo) [0x0000d] in <cd67dccacaf74fda9b96645f718f622c>:0 
Error	7776	AndroidRuntime	  at Visao.AC_Pedido..ctor () [0x0001a] in <cd67dccacaf74fda9b96645f718f622c>:0 
Error	7776	AndroidRuntime	  at Persistencia.ModelBase.BaseToInstance (System.Boolean com_chave, System.Boolean loadByDate) [0x00010] in <188c5af2ae56445c80c728e34f5d043d>:0 
Error	7776	AndroidRuntime	Process: com.landix.sfv, PID: 7776
Error	7776	AndroidRuntime		at java.lang.Class.newInstance(Class.java:1606)
Error	7776	AndroidRuntime	Caused by: java.lang.reflect.InvocationTargetException
Error	7776	AndroidRuntime	FATAL EXCEPTION: main
Error	7776	AndroidRuntime		... 1 more
Error	7776	AndroidRuntime		at java.lang.reflect.Constructor.newInstance(Native Method)
Error	7776	AndroidRuntime		at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
Error	7776	AndroidRuntime		at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2240)
Error	7776	AndroidRuntime		at android.app.Instrumentation.newActivity(Instrumentation.java:1089)
Error	7776	AndroidRuntime	   --- End of inner exception stack trace ---
Debug	7776	AndroidRuntime	Shutting down VM
Warning	7776	art	JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
Info	7776	MonoDroid	  at Persistencia.ModelBase.Load () [0x00000] in <188c5af2ae56445c80c728e34f5d043d>:0 
Info	7776	MonoDroid	  at Modelo.MD_Parametros.get_Perfil () [0x00008] in <cd67dccacaf74fda9b96645f718f622c>:0 
Info	7776	MonoDroid	  at Java.Interop.TypeManager.n_Activate (System.IntPtr jnienv, System.IntPtr jclass, System.IntPtr typename_ptr, System.IntPtr signature_ptr, System.IntPtr jobject, System.IntPtr parameters_ptr) [0x00189] in <07cc2c8668cc4cf4b0b334d25424a46d>:0 
Info	7776	MonoDroid	  at (wrapper dynamic-method) System.Object:b86a0d8b-9e30-472a-9412-631ae5bf579c (intptr,intptr,intptr,intptr,intptr,intptr)
Info	7776	MonoDroid	  at (wrapper dynamic-method) System.Object:3baf69a6-fd8a-4e08-84e6-533dc4b76e25 (intptr,object[])
Info	7776	MonoDroid	  at Visao.AC_Pedido..ctor () [0x0001a] in <cd67dccacaf74fda9b96645f718f622c>:0 
Info	7776	MonoDroid	  at Modelo.MDN_Perfil..ctor (System.String codigo) [0x0000d] in <cd67dccacaf74fda9b96645f718f622c>:0 
Info	7776	MonoDroid	  at Java.Interop.TypeManager.n_Activate (System.IntPtr jnienv, System.IntPtr jclass, System.IntPtr typename_ptr, System.IntPtr signature_ptr, System.IntPtr jobject, System.IntPtr parameters_ptr) [0x000fb] in <07cc2c8668cc4cf4b0b334d25424a46d>:0 
Info	7776	MonoDroid	System.NotSupportedException: Could not activate JNI Handle 0xbebcbdc8 (key_handle 0x26df4146) of Java type 'md5044160bdd3b04941689b7308e2483e28/AC_Pedido' as managed type 'Visao.AC_Pedido'. ---> System.NullReferenceException: Object reference not set to an instance of an object
Info	7776	MonoDroid	   --- End of inner exception stack trace ---
Info	7776	MonoDroid	  at Persistencia.ModelBase.BaseToInstance (System.Boolean com_chave, System.Boolean loadByDate) [0x00010] in <188c5af2ae56445c80c728e34f5d043d>:0 
Info	7776	MonoDroid	UNHANDLED EXCEPTION:
Warning	7776	monodroid	Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Warning	7776	monodroid	Could not activate JNI Handle 0xbebcbdc8 (key_handle 0x26df4146) of Java type 'md5044160bdd3b04941689b7308e2483e28/AC_Pedido' as managed type 'Visao.AC_Pedido'.
Warning	7776	art	JNI RegisterNativeMethods: attempt to register 0 native methods for md5e59e43211bc2cbaf8cd09b8093007196.MD_Application12-07 16:17:04.959	Motorola XT1021	Warning	7776	monodroid	Calling into managed runtime init
Warning	7776	monodroid-gc	GREF GC Threshold: 46080
Warning	7776		0x2b841fc3 0xee1dd804 0xf8511f70 0x47700020 0x47702000 0x4604b537 0x460da801 0xff1af7ff 0x2b841fe3 0x4620d803 0xff02f7ff 0x2416b908 0xee1de004 0xf8400f70 0x24005024 0x44784803 
Warning	7776		No fast tls on device. Using fallbacks. Current implementation : 
Warning	7776	monodroid-debug	Not starting the debugger as the timeout value has been reached; current-time: 1512670624  timeout: 1512645070
Warning	7776	ResourcesManager	Asset path '/system/framework/com.google.android.maps.jar' does not exist or contains no resources.

Versions:
Visual Studio 2015 
Xamarin 4.2.0
Xamarin.Android 7.0.0.18
Android Version 5.1 (Lollipop) Also simulated on other android versions
Comment 1 Marek Habersack 2017-12-08 17:43:34 UTC
@Luan so the core issue here is:

> Info	7776	MonoDroid	System.NotSupportedException: Could not activate JNI Handle 0xbebcbdc8 (key_handle 0x26df4146) of Java type 'md5044160bdd3b04941689b7308e2483e28/AC_Pedido' as managed type 'Visao.AC_Pedido'. ---> System.NullReferenceException: Object reference not set to an instance of an object
> Info	7776	MonoDroid	   --- End of inner exception stack trace ---
> Info	7776	MonoDroid	  at Persistencia.ModelBase.BaseToInstance (System.Boolean com_chave, System.Boolean loadByDate) [0x00010] in <188c5af2ae56445c80c728e34f5d043d>:0 

This suggests that somewhere along the way one of objects in your app gets garbage collected and then an attempt is made to use it again, thus throwing the exception and causing the issue. This might be due to the fact that a reference to a *Java* object isn't held properly and the managed object goes away with it, or exactly the other way around. There might be other reasons too. Alas, it's nearly impossible to tell what's going on without a repro. Would you be able to extract the smallest repro possible from your app and attach it here (a small, standalone app that reproduces the issue)?