Mvvmcross: [Android] MvxSplashScreenActivity should not have to be the first Activity

Created on 11 Oct 2017  路  7Comments  路  Source: MvvmCross/MvvmCross

It's a bit ridiculous that MvxSplashScreenActivity is a required part of the startup process on Android, as this means that you cannot put intent filters on other activities.

Eg. We have a SplashScreen activity and a MainActivity, MainActivity is where we initialize MvvmCross and Xamarin.Forms (obviously), so we put an intent filter with a custom data scheme so that we can associate our app with custom Uri's.
Using adb shell am start -a android.intent.action.VIEW -d [custom.uri.scheme] while the app is backgrounded works just fine, however if the app is forcibly terminated using the task manager, the same command will cause the activity to instantly bomb out. Checking logcat shows that Xamarin.Forms.Forms.GetAccentColor is throwing a null reference exception as part of the Mvx startup process.

When the intent filter is moved to the SplashScreen activity, this issue no longer occurs, but in order to pass the data to our MainActivity we now have to create a bundle every time for the navigation from SplashScreen to MainActivity.

MvvmCross should be entirely functional without having to run MvxSplashScreenActivity so that complex apps with intent filters and data associations can be made using the framework, anything that happens in MvxSplashScreenActivity should be moved further down the chain so that it is no longer required.

android forms deprecated feature

Most helpful comment

Yes this is definitely specific to Forms. And yes, I think this has now been fixed. I just ran through creating a new XF application with Mvx and it all worked ok without a splash screen (https://nicksnettravels.builttoroam.com/post/2017/12/27/Getting-Started-MvvmCross-with-Xamarin-Forms-(Part-2).aspx)

All 7 comments

Hey, thanks for reporting this with a very detailed explanation (although you didn't use the issue template).

I think it shouldn't be _that_ hard to override the standard behavior and get rid of the SplashScreen.

That said, we really want to improve how the framework works on this situation (at least document how to override the default behavior). So any contribution is very much appreciated :)

I've been digging a little more on this.

Honestly I don't think a SplashScreen is needed in all cases. If you take a look at the Eventhooks TestProject, it doesn't use one and everything works fine.

The only thing that is probably implicit, is that you need to manually call IMvxAppStart.Start if you don't use a SplashScreen.

Can you please provide us more information? Some code / repro case will be very appreciated. Maybe there is a Forms View type that is not ensuring Mvx is available.

I have a somehow similar problem.
If we have a proxy activity which is used to redirect intents (Post, Pick ,..) to the MainActivity, while the app process is killed or starting as a new one, after starting the MainActivity using StartActivity(intent), the MainViewModel will not initialize properly (Task Initialize() method not being called).
Although, I know MvvmCross uses viewmodel first approach, still I could not find a proper way to handle such situations.

I am having the same problems. Does anybody knows the solution, workaround, please?

Hi @AdelaPetrut , I've managed a workaround by making sure that any IntentFilter that I use is only ever set up on my activity that inherits MvxSplashScreenActivity, so that that is the first activity to launch.

Then, if I need to pass any arguments to another activity, I can override InitializationComplete() in my SplashScreenActivity, and pass any Data or Extras in to the next activity like so:

var intent = new Intent(this, typeof(MainActivity));
intent.SetData(Intent.Data);
StartActivity(intent);

As long as you make sure to put everything that you will require into the new Intent, this should work as expected, although there will obviously be quite a bit longer of a delay when launching your app via Intent filters, as all of the startup tasks that occur in MvxSplashScreenActivity need to happen, as well as any other initialisation that you need to do (in addition to any initialisation you need to do for your next activity).

Ok so reading the issue description for a second time, I realize this issue is more of a Xamarin Forms issue than an Android one (Please use the issue template!).

In the case of Xamarin.Android, a splash screen is not necessary at all. We could/should improve the docs arount that, but that is surely out of the scope of this issue.

In the case of Forms, could it be that #2454 (--> #2457) removed this limitation? (cc: @nickrandolph / @martijn00).

Yes this is definitely specific to Forms. And yes, I think this has now been fixed. I just ran through creating a new XF application with Mvx and it all worked ok without a splash screen (https://nicksnettravels.builttoroam.com/post/2017/12/27/Getting-Started-MvvmCross-with-Xamarin-Forms-(Part-2).aspx)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fedemkr picture fedemkr  路  4Comments

HaraldMuehlhoffCC picture HaraldMuehlhoffCC  路  3Comments

a7ex picture a7ex  路  3Comments

Cheesebaron picture Cheesebaron  路  4Comments

andbaciu picture andbaciu  路  3Comments