Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Android OnStart crash only on specific usecase #10668


User avatar
0
Ricavir created

Xamarin Forms 4.8 Abp 6.4

Hi @Alper,

A lot of users are getting more and more exceptions on Xamarin Forms Android app like this : https://support.aspnetzero.com/QA/Questions/8484/Android-OnStart-crash The app is on the play store since a long time now and is working well most of the time. I never found the way to reproduce the exception reported by Google... but some days ago we had these exceptions with a new Nexus 5.

Therefore I hope you can help me to found a solution and fix the issue with the details above :

The exception happens in the following usecase :

  • app is running normaly on foreground
  • app is now in background
  • after some time in background, the OS may kill the process (due to timeout or memory space needed)
  • user comes back to the app
  • app starts with the splash screen
  • after splash screen is closed, the app crash
  • user can reopen the app after the crack without any issue
  • this exception is not happening when the app is killed manualy by the user

Here is the Android exception logged :


> 11-06 06:37:48.437 11020 11020 E AndroidRuntime: FATAL EXCEPTION: main
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime: Process: com.MyApp.Mobile, PID: 11020
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime: android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:   at MyORG.MyApp.Core.Dependency.DependencyResolver.Resolve[T] () [0x00005] in <1174882f65d4478c861b92e9fc0bd083>:0
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:   at MyORG.MyApp.App.OnStart () [0x0010a] in <1174882f65d4478c861b92e9fc0bd083>:0
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <1b39a03c32ec46258a7821e202e0269f>:0
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:   at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <b868e022fd60450992c00cdaff974113>:0
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <b868e022fd60450992c00cdaff974113>:0
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <b868e022fd60450992c00cdaff974113>:0
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.37(intptr,intptr)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at mono.java.lang.RunnableImplementor.n_run(Native Method)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:938)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at android.os.Looper.loopOnce(Looper.java:201)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:288)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7842)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
> 11-06 06:37:48.437 11020 11020 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

The exception seems to happen while calling :

await DependencyResolver.Resolve<INavigationService>().InitializeAsync();

Do you know why INavigationService could be null only on app restarts in that specific usecase ?

Could this be linked with the SplashActivity OnResume() when calling

ApplicationBootstrapper.InitializeIfNeeds<XamarinAndroidModule>()

.


5 Answer(s)
  • User Avatar
    0
    Ricavir created

    I tried to replace ApplicationBootstrapper.InitializeIfNeeds<XamarinAndroidModule>() by a new method called ApplicationBootstrapper.Initialize<XamarinAndroidModule>() which initialize application IOC container each time.

    At first, it seems to be better but I had an app crash as follows :

    11-07 17:49:32.384 31604 31604 E AndroidRuntime: android.runtime.JavaProxyThrowable: System.ArgumentException: Facility of type 'Castle.Facilities.Logging.LoggingFacility' has already been registered with the container. Only one facility of a given type can exist in the container.
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at Castle.MicroKernel.DefaultKernel.AddFacility (Castle.MicroKernel.IFacility facility) [0x0004e] in <e8e139fd05dd4c49be84efef707f01f4>:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at Castle.MicroKernel.DefaultKernel.AddFacility[T] (System.Action`1[T] onCreate) [0x00010] in &lt;e8e139fd05dd4c49be84efef707f01f4&gt;:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at Castle.Windsor.WindsorContainer.AddFacility[T] (System.Action`1[T] onCreate) [0x00000] in <e8e139fd05dd4c49be84efef707f01f4>:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at MyORG.MyApp.Core.ApplicationBootstrapper.Initialize[T] () [0x00038] in <3139bd716c9d44ebbfcb67ec47cb44cb>:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at MyORG.MyApp.Activities.SplashActivity.OnResume () [0x00017] in <e77a7bfb8b904473b3eb7dd998dd0ff6>:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in <1b39a03c32ec46258a7821e202e0269f>:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <b868e022fd60450992c00cdaff974113>:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <b868e022fd60450992c00cdaff974113>:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <b868e022fd60450992c00cdaff974113>:0
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.38(intptr,intptr)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at mono.java.lang.RunnableImplementor.n_run(Native Method)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:938)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at android.os.Looper.loopOnce(Looper.java:201)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:288)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7842)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    11-07 17:49:32.384 31604 31604 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    

    So it tells that I can't register a new Container...

    Do you have any idea to help me find this bugg ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ricavir

    Can you reproduce this problem on development time ? Could you create an issue on GitHub so we can work on this for the next version ?

    Thanks,

  • User Avatar
    0
    Ricavir created

    Hi @ismcagdas,

    Thks for your feedback. I was not able to reproduce in development. I created an issue on github : https://github.com/aspnetzero/aspnet-zero-core/issues/4088

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks, I have added it to next milestone. We will work on this issue right after releasing .NEt 6 version of AspNet Zero.

  • User Avatar
    0
    Ricavir created

    Great @ismcagdas, we can close this ticket and follow the Github issue.