NullReferenceException on Xamarin Droid App startup - android

I am facing a NullReferenceException when starting an Xamarin Android App via Visual Studio 2015.
It is thrown after leaving the OnCreate() in my main activity, but I do not know where and why. How can find more information about this error?
The Debug output is like this:
05-21 20:18:51.643 D/OpenGLRenderer(25574): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-21 20:18:51.651 D/Atlas (25574): Validating map...
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
Exception:
System.NullReferenceException: Object reference not set to an instance of an object
05-21 20:19:37.436 D/Mono (25574): DllImport attempting to load: '/system/lib/liblog.so'.
05-21 20:19:37.436 D/Mono (25574): DllImport loaded library '/system/lib/liblog.so'.
05-21 20:19:37.436 D/Mono (25574): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
05-21 20:19:37.436 D/Mono (25574): Searching for '__android_log_print'.
05-21 20:19:37.436 D/Mono (25574): Probing '__android_log_print'.
05-21 20:19:37.437 D/Mono (25574): Found as '__android_log_print'.
05-21 20:19:37.450 I/MonoDroid(25574): UNHANDLED EXCEPTION:
05-21 20:19:37.454 I/MonoDroid(25574): System.NullReferenceException: Object reference not set to an instance of an object
05-21 20:19:37.454 I/MonoDroid(25574): at Xamarin.Forms.Platform.Android.KeyboardManager.HideKeyboard (Android.Views.View inputView, Boolean overrideValidation) [0x00000] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\KeyboardManager.cs:14
05-21 20:19:37.454 I/MonoDroid(25574): at Xamarin.Forms.Platform.Android.FormsApplicationActivity.OnPause () [0x00000] in C:\BuildAgent3\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\FormsApplicationActivity.cs:153
05-21 20:19:37.455 I/MonoDroid(25574): at Android.App.Activity.n_OnPause (IntPtr jnienv, IntPtr native__this) [0x00009] in /Users/builder/data/lanes/3236/ee215fc9/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:4046
05-21 20:19:37.455 I/MonoDroid(25574): at (wrapper dynamic-method) System.Object:5c198319-5b9a-4152-9518-5aa3ce7cab6e (intptr,intptr)
05-21 20:19:37.476 W/art (25574): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
An unhandled exception occured.
05-21 20:19:38.791 E/mono (25574):
05-21 20:19:38.791 E/mono (25574): Unhandled Exception:
05-21 20:19:38.791 E/mono (25574): System.NullReferenceException: Object reference not set to an instance of an object
05-21 20:19:38.791 E/mono (25574): at (wrapper dynamic-method) System.Object:5c198319-5b9a-4152-9518-5aa3ce7cab6e (intptr,intptr)
05-21 20:19:38.791 E/mono (25574): at (wrapper native-to-managed) System.Object:5c198319-5b9a-4152-9518-5aa3ce7cab6e (intptr,intptr)
05-21 20:19:38.792 E/mono-rt (25574): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
05-21 20:19:38.792 E/mono-rt (25574): at (wrapper dynamic-method) System.Object:5c198319-5b9a-4152-9518-5aa3ce7cab6e (intptr,intptr)
05-21 20:19:38.792 E/mono-rt (25574): at (wrapper native-to-managed) System.Object:5c198319-5b9a-4152-9518-5aa3ce7cab6e (intptr,intptr)
referenceTable GDEF length=670 1
referenceTable GSUB length=7202 1
referenceTable GPOS length=24560 1

I know it's been a while but perhaps I can help someone in the future. Something similar happened to me when I accidentally removed the initiation of my App.Current.Mainpage while the app was starting up. Silly mistake that leads to an unhelpful error message.
Got the idea on where my problem was from here: https://bugzilla.xamarin.com/show_bug.cgi?id=36287

Related

Does the Visual Studio emulator for Android support OpenGL ES 3.0?

I develped an OpenGL ES 3.0 app with Xamarin.Android. It runs well on my phone but crashed on the VS emulator for Android.
It crashes here:
at (wrapper managed-to-native) OpenTK.Graphics.ES30.GL/Core.CreateShader (OpenTK.Graphics.ES30.All) <0x00012>
And an error occurs before:
E/EGL_emulation( 1977): tid 1977: eglGetConfigAttrib(606): error 0x3004 (EGL_BAD_ATTRIBUTE)
I wonder if the simluator doesn't support OpenGL ES 3.0.
In the OpenGL ES Support section of this post,
VS Emulator for Android can now render apps that make use of OpenGL ES up to version 2.0
So, does the Visual Studio emulator for Android support OpenGL ES 3.0?
related logs:
D/Mono ( 1977): Found as 'java_interop_jnienv_get_object_array_element'.
E/EGL_emulation( 1977): [getAttribValue] Bad attribute idx
E/EGL_emulation( 1977): tid 1977: eglGetConfigAttrib(606): error 0x3004 (EGL_BAD_ATTRIBUTE)
D/Mono ( 1977): DllImport searching in: '__Internal' ('(null)').
D/Mono ( 1977): Searching for 'java_interop_jnienv_get_field_id'.
D/Mono ( 1977): Probing 'java_interop_jnienv_get_field_id'.
D/Mono ( 1977): Found as 'java_interop_jnienv_get_field_id'.
D/Mono ( 1977): DllImport searching in: '__Internal' ('(null)').
D/Mono ( 1977): Searching for 'java_interop_jnienv_get_int_field'.
D/Mono ( 1977): Probing 'java_interop_jnienv_get_int_field'.
D/Mono ( 1977): Found as 'java_interop_jnienv_get_int_field'.
D/Mono ( 1977): Assembly Ref addref Xamarin.OpenGL[0xb42b90a0] -> System[0x9e581dc0]: 4
D/Mono ( 1977): Assembly Ref addref Xamarin.OpenGL[0xb42b90a0] -> System.Core[0x9d8b71c0]: 4
Resolved pending breakpoint at 'ShaderProgram.cs:27,1' to void CSharpGLES.ShaderProgram.Create (string vertexShaderSource, string fragmentShaderSource, System.Collections.Generic.Dictionary<int,string> attributeLocations) [0x00001].
D/Mono ( 1977): DllImport attempting to load: 'GLESv2'.
D/Mono ( 1977): DllImport error loading library './libGLESv2': 'dlopen failed: library "/data/app/Xamarin.OpenGL.Xamarin.OpenGL-1/lib/x86/./libGLESv2" not found'.
D/Mono ( 1977): DllImport loaded library './libGLESv2.so'.
D/Mono ( 1977): DllImport searching in: 'GLESv2' ('./libGLESv2.so').
D/Mono ( 1977): Searching for 'glCreateShader'.
E/mono-rt ( 1977): Stacktrace:
E/mono-rt ( 1977):
E/mono-rt ( 1977): at <unknown> <0xffffffff>
E/mono-rt ( 1977): at (wrapper managed-to-native) OpenTK.Graphics.ES30.GL/Core.CreateShader (OpenTK.Graphics.ES30.All) <0x00012>
E/mono-rt ( 1977): at OpenTK.Graphics.ES30.GL.CreateShader (OpenTK.Graphics.ES30.All) [0x00002] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/OpenGLES/OpenTK/Graphics/ES30.Android/GL.cs:1559
Related:
Does the Android Emulator support OpenGL ES 2.0?
Does the Android emulator support OpenGL ES 3.0?
Someone has found the answer for me: OpenGLES 3.0 hasn't been supported.
from https://blogs.msdn.microsoft.com/visualstudioalm/2015/02/23/the-visual-studio-emulator-for-android-in-vs2015-ctp6/
... the VS Emulator for Android can now render apps that make use of OpenGL ES > up to version 2.0. .... (If you’re curious, under the hood we’re forwarding
OpenGL ES calls to the host machine’s GPU and using ANGLE to translate the
calls to DirectX).
from ANGLE (https://chromium.googlesource.com/angle/angle/+/master/README.md)
still not fully support GLES3.0 (in progress).
so It may cause the error on shader compilation on the emulator.
Update:
A staff member of MS told me in another site that the driver of the emulator hasn't supported OpenGLES 3.0. So currently the emulator won't support OpenGL ES 3.0 even if ANGLE does support.

Xamarin.Forms MissingMethodException: 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found

I have followed everything from the following link:
https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/
The code I wrote can be found here: http://github.com/foyzulkarim/XamarinFormsDrawer
I successfully deployed the same project in my Windows 10 Local machine using UWP project, but whenever I want to deploy in Emulator, or in my device, it is throwing the following exception.
System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
09-17 17:16:33.636 D/Mono (10472): DllImport attempting to load: '/system/lib/liblog.so'.
09-17 17:16:33.637 D/Mono (10472): DllImport loaded library '/system/lib/liblog.so'.
09-17 17:16:33.637 D/Mono (10472): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
09-17 17:16:33.637 D/Mono (10472): Searching for '__android_log_print'.
09-17 17:16:33.637 D/Mono (10472): Probing '__android_log_print'.
09-17 17:16:33.637 D/Mono (10472): Found as '__android_log_print'.
09-17 17:16:33.645 I/MonoDroid(10472): UNHANDLED EXCEPTION:
09-17 17:16:33.658 I/MonoDroid(10472): System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
09-17 17:16:33.658 I/MonoDroid(10472): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\Platform.cs:282
09-17 17:16:33.658 I/MonoDroid(10472): at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement view) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\RendererFactory.cs:10
09-17 17:16:33.658 I/MonoDroid(10472): at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page page, System.Boolean layout) [0x00015] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:248
09-17 17:16:33.658 I/MonoDroid(10472): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x00089] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:237
09-17 17:16:33.658 I/MonoDroid(10472): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0009b] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:336
09-17 17:16:33.658 I/MonoDroid(10472): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:410
09-17 17:16:33.659 I/MonoDroid(10472): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x00158] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:123
09-17 17:16:33.659 I/MonoDroid(10472): at App1.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00018] in C:\Users\foyzu\Source\Github\XamarinForms\XamarinFormsDrawer\App1\App1\App1.Droid\MainActivity.cs:23
09-17 17:16:33.659 I/MonoDroid(10472): at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <71c3e52f1b484794bca1cdfb1b8b1fdb>:0
09-17 17:16:33.659 I/MonoDroid(10472): at (wrapper dynamic-method) System.Object:1a87dfa6-a154-49b0-925d-8ddad74d97cf (intptr,intptr,intptr)
09-17 17:16:33.677 W/art (10472): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
09-17 17:16:33.681 D/Mono (10472): DllImport searching in: '__Internal' ('(null)').
09-17 17:16:33.681 D/Mono (10472): Searching for 'java_interop_jnienv_throw'.
09-17 17:16:33.681 D/Mono (10472): Probing 'java_interop_jnienv_throw'.
09-17 17:16:33.681 D/Mono (10472): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.
09-17 17:16:34.399 E/mono (10472):
09-17 17:16:34.399 E/mono (10472): Unhandled Exception:
09-17 17:16:34.399 E/mono (10472): System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
09-17 17:16:34.399 E/mono-rt (10472): [ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
referenceTable GDEF length=814 1
referenceTable GSUB length=11364 1
referenceTable GPOS length=47302 1
The solution is, I needed to update the package, only the Xamarin.Forms package. Like the below image.
After update, the packages.config file should be like below
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Forms" version="2.3.2.127" targetFramework="monoandroid60" />
</packages>
And ignore the rest of the packages like below.
Just update your nuget-packages to latest (Xamarin.forms too)
clean solution
close the visualstudio
delete all .zip files in:
C:\Users[YouUserName]\AppData\Local\Xamarin\zips
Restart visualstudio and recompile :) It will download those .zip files again (it may take a few minutes). Those zips includes related android support libraries. So it will download the true ones (your referenced xamarin.forms version related).
Updating the Xamarin.Forms nuget package didn't work for me. In my case, an update of Android Studio was necessary to make Xamarin.Forms work with Visual Studio. After updating, restart Android Studio and do look for updates again and apply them if they get found. You need to keep repeating this, because not all updates get installed in one go. This was my case, at least.
I suppose this worked, because Android Studio contains the Android SDK or some other components which Visual Studio or Xamarin need.
Most of Cases You need to update the Xamarin.Forms Package to the latest Version
on all your projects( To avoid Other Exceptions)
For Portable, .Driod,.IOS and for Windows Phone if exist, then it is mandatory to clean your solution and close visual studio and open it again, Finlay every thing will be fine.
But On Some Cases you need to downgrade your Xamarin.Forms Package to 2.3 instead 2.5.0.121934

Libgdx Android – Process has died with no erros

In the middle of the game, it closes without showing any erros.
How to identify what is causing this behavior?
I removed all exit commands on the code and still closes.
LogCat:
All Messages:
05-20 09:21:16.785: I/ActivityManager(27603): Process com.xxxx.yyyy.android (pid 13684) has died.
On the process (PID 13684):
No errors.
No warnings.
No messages, just the normal game System.out
If I just close the game, the message on LogCat is the same.
Another device shows the errors on logCat of the process:
Note: the file numbers/2.png is ok and normally used on the Game.
05-21 08:00:54.398: E/libutils.threads(14116): androidCreateRawThreadEtc failed (entry=0x4017cf20, res=11, errno=0)
05-21 08:00:54.398: E/libutils.threads(14116): (android threadPriority=-16)
05-21 08:00:54.708: A/libc(14116): malloc size: 695556
05-21 08:00:55.218: E/AndroidRuntime(14116): FATAL EXCEPTION: GLThread 15797
05-21 08:00:55.218: E/AndroidRuntime(14116): Process: com.dsgames.combinations2048.android, PID: 14116
05-21 08:00:55.218: E/AndroidRuntime(14116): com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: numbers/2.png
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:148)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:88)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.xxxx.yyyy.GameScreen.touchDown(GameScreen.java:2573)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.InputMultiplexer.touchDown(InputMultiplexer.java:90)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.backends.android.AndroidInput.processEvents(AndroidInput.java:375)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:470)
05-21 08:00:55.218: E/AndroidRuntime(14116): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1527)
05-21 08:00:55.218: E/AndroidRuntime(14116): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1244)
05-21 08:00:55.218: E/AndroidRuntime(14116): Caused by: java.io.IOException: Error loading pixmap: decoder init failed for stream
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.graphics.g2d.Gdx2DPixmap.<init>(Gdx2DPixmap.java:90)
05-21 08:00:55.218: E/AndroidRuntime(14116): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:146)
05-21 08:00:55.218: E/AndroidRuntime(14116): ... 10 more
05-21 08:00:59.698: E/AndroidGraphics(14116): waiting for pause synchronization took too long; assuming deadlock and killing
I discovered the problem. Every click on the screen, I created a new texture without making a dispose of the others. It was memory usage issue.
I think the line A / libc (14116): malloc size: 695 556 indicates this.
The question that remains is:
Why in one device did not generate error, only closed the game?

Android(mono), TypeLoadException : " Could not load type 'CameraInfo' "

I used the below code piece to read barcode using Zxing barcode library which is downloaded from http://components.xamarin.com/gettingstarted/zxing.net.mobile. Application minVersion is selected as 2.3 and target version is selected as Automatic. I'am running the app on nexus 4 (Android 4.4.2)
BarcodeButton.Click += async delegate
{
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
var result = await scanner.Scan();
if (result != null)
Toast.MakeText(this,"DONE",ToastLength.Short).Show();
};
When I run the application, after pressing the barcodebutton this error log is obtained. What is the error? How can I solve it? :
...
[Mono] Assembly Ref addref ZXing.Net.Mobile[0x784bb038] -> mscorlib[0x777e2a10]: 9
[Mono] Assembly Ref addref TeleLib[0x784b8c58] -> zxing.monoandroid[0x784ba440]: 2
[Mono] The request to load the assembly mscorlib v2.0.5.0 was remapped to v2.0.0.0
[Mono] Unloading image mscorlib.dll [0x78801068].
[Mono] Assembly Ref addref zxing.monoandroid[0x784ba440] -> mscorlib[0x777e2a10]: 10
[Mono] Assembly Ref addref ZXing.Net.Mobile[0x784bb038] -> Mono.Android[0x784bbb98]: 4
[Mono] Assembly Ref addref ZXing.Net.Mobile[0x784bb038] -> zxing.monoandroid[0x784ba440]: 3
[Mono] Assembly Ref addref ZXing.Net.Mobile[0x784bb038] -> Xamarin.Android.Support.v4[0x784b9848]: 2
[Mono] Assembly Ref addref zxing.monoandroid[0x784ba440] -> Mono.Android[0x784bbb98]: 5
[] TypeRef ResolutionScope not yet handled (14) for .CameraInfo in image /data/data/TeleLib.TeleLib/files/.__override__/ZXing.Net.Mobile.dll
[Mono] The class CameraInfo could not be loaded, used in
[MonoDroid] UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'CameraInfo'.
[MonoDroid] at Android.Views.ISurfaceHolderCallbackInvoker.n_SurfaceCreated_Landroid_view_SurfaceHolder_ (intptr,intptr,intptr) <0x0005f>
[MonoDroid] at (wrapper dynamic-method) object.c17a61df-f7d9-45dc-ba1c-dac5c5d9eb39 (intptr,intptr,intptr) <0x00043>
[mono]
[mono] Unhandled Exception:
[mono] System.TypeLoadException: Could not load type 'CameraInfo'.
[mono] at Android.Views.ISurfaceHolderCallbackInvoker.n_SurfaceCreated_Landroid_view_SurfaceHolder_ (IntPtr jnienv, IntPtr native__this, IntPtr native_holder) [0x00000] in <filename unknown>:0
[mono] at (wrapper dynamic-method) object:c17a61df-f7d9-45dc-ba1c-dac5c5d9eb39 (intptr,intptr,intptr)
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'CameraInfo'.
[mono-rt] at Android.Views.ISurfaceHolderCallbackInvoker.n_SurfaceCreated_Landroid_view_SurfaceHolder_ (IntPtr jnienv, IntPtr native__this, IntPtr native_holder) [0x00000] in <filename unknown>:0
[mono-rt] at (wrapper dynamic-method) object:c17a61df-f7d9-45dc-ba1c-dac5c5d9eb39 (intptr,intptr,intptr)
I was running into the same issue and figured out that the ZXing.NET component requires Android version 2.3. Change your project to target 2.3 or newer, and this error will go away.

Monodroid - GC.Collect fails without any reason

I have an application with 4 tabs (TabActivity). By some reasons I call GC.Collect every time user switches tab (overriding OnPause Activity's method). Sometimes (approximately 1 time from 50-100 calls, but sometimes this happens when application just started) my application hangs in this moment.
Here is part of my code:
protected override void OnPause(){
base.OnPause();
try{
Android.Util.Log.Info("----","GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);");
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
Android.Util.Log.Info("----","GC.Collect Finished");
}catch(Exception exc){
Android.Util.Log.Info("exc.Message",exc.Message);
Android.Util.Log.Info("exc.StackTrace",exc.StackTrace);
throw exc;
}
}
And here is corresponding Android log output
//Previous GC.Collect call, it's all ok
I/---- ( 7796): GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
D/dalvikvm( 7796): GetMethodID: method not found: Landroid/widget/EditText;.monodroidAddReference:(Ljava/lang/Object;)V
D/dalvikvm( 7796): GC_EXPLICIT freed 962 objects / 42472 bytes in 112ms
I/---- ( 7796): GC.Collect Finished
//On another call fails
I/---- ( 7796): GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
I/mono ( 7796): Stacktrace:
I/mono ( 7796):
I/mono ( 7796): at System.GC.Collect (int) <0x0001f>
I/mono ( 7796): at System.GC.Collect (int,System.GCCollectionMode) <0x00017>
I/mono ( 7796): at PixelsAndroid.CustomActivity.OnPause () <0x00067>
I/mono ( 7796): at Android.App.Activity.n_OnPause (intptr,intptr) <0x00037>
I/mono ( 7796): at (wrapper dynamic-method) object.908cefd4-40eb-4dd1-97cd-f731b2ada74a (intptr,intptr) <0x0002b>
I/mono ( 7796): at (wrapper native-to-managed) object.908cefd4-40eb-4dd1-97cd-f731b2ada74a (intptr,intptr) <0xffffffff>
No any exception to been thrown, no any visible reason to fail. Application just hangs, after few seconds I get Android OS alert: "Oppps, your application got stuck. Force close or wait?"
Anybody faced with it?
There was a bug in some old versions of monodroid: if you call GC.Collect and an http request in a parallel threads, this caused crash. Update to a latest version of monodroid.
Having to do a GC.Collect() under any circumstance is a bad code smell. Figure out the underlying reason and perform corrective rearchitecture.

Categories

Resources