pde
pde

Reputation: 11

Xamarin Android app built using MvvmCross stuck on splash screen when resumed from background after 3-4 days

I am working on one Xamarin Android project which is using MvvmCross version 3.5.1. I am facing one issue which we thought might be because of MvvmCross set up failure. App is basically for both platforms Android and iOS. But, i am facing an issue specifically for Android. App is quite old and in development from last 3-4 years and never upgraded to latest released versions of MvvmCross. Updating MvvmCross is last option for me. But before that I want to fix this issue by knowing it's root cause and way to reproduce it.

Scenario:

1) App installed on Android device, Login is done.

2) App moved to background.

3) After 3-4 days, app resumed by clicking on app launcher icon and stuck on splash screen.

4) App started working again when
force stop from phone setting

I am unable to reproduce this issue without putting it in the background for more than 3-4 days. Can you please suggest a few approaches to know the root cause and steps to reproduce this issue without putting the app in background for more than 4 days.

Below Logs printed from MvvmCross and app freezes on the splash screen. log statement in bold "No view model type finder available - assuming we are looking for a splash screen - returning null" is printed 3-4 times and then app stuck on splash screen. Even though app stuck on splash screen. push notifications are received by an application.

Setup: PlatformServices start"

Setup: MvvmCross settings start"

Setup: Singleton Cache start"

"mvx": "No view model type finder available - assuming we are looking for a splash screen - returning null"

"mvx": "No view model type finder available - assuming we are looking for a splash screen - returning null"

"mvx": "No view model type finder available - assuming we are looking for a splash screen - returning null"

Please help me to know why the above log statement in bold is getting printed for 3-4 times and why logs from _setup.InitializeSecondary() are not printed, and then app stucks on splash. Looks like setup hung in between because of some deadlock or race condition. It will really help me if you have any suggestions to know possibilities to know the root cause and a way to reproduce this issue. Thanks in advance.

Updated: We are able to reproduced this scenario by commenting InitializeSecondary() call from MvxAndroidSetupSingleton->InitializeFromSplashScreen() and app stuck on Splash screen. please suggest fixing this splash screen stuck from app level code. Basically, we don't want to modify MvvmCross code and wanted to fix from app code. Your help is appreciated. As per logs, a line of code _setup.InitializeSecondary(); in below method from MvxAndroidSetupSingleton.cs is not executed. This issue is getting reproduced only after keeping the application in the background for more than 4-5 days. First i am trying to know why this is happening in this particular case and then solution for it. Thanks in advance

Note: I am using Android Foreground service in my application

public virtual void InitializeFromSplashScreen(IMvxAndroidSplashScreenActivity splashScreen) { lock (LockObject) { _currentSplashScreen = splashScreen;

            if (_initializationStarted)
            {
                if (_initialized)
                {
                    _currentSplashScreen.InitializationComplete();
                    return;
                }

                return;
            }

            _initializationStarted = true;
        }

        _setup.InitializePrimary();

        ThreadPool.QueueUserWorkItem(ignored =>
        {
            _setup.InitializeSecondary();

            lock (LockObject)
            {
                _initialized = true;
                if (_currentSplashScreen != null)
                    _currentSplashScreen.InitializationComplete();
            }
        });
    }

Upvotes: 1

Views: 1117

Answers (2)

BrunoVT
BrunoVT

Reputation: 723

Android will memory clear an app if it is long in the background and or unused. This means that the mvvm framework loses all of its references in memory as the same for your IOC Container. Normally an mvvm framework should be able to handle this but in my experience sometimes you have to manually give it a push.

Upvotes: 0

Cheesebaron
Cheesebaron

Reputation: 24460

We have made a lot of improvements to app startup in MvvmCross. So chances are that your issue has been solved in a newer version.

Although, since it is saying "No view model type filder available", it will probably mean that the startup procedure hasn't finished or is stuck doing something and cannot find the next ViewModel it wants to continue to.

Upvotes: 2

Related Questions