1
votes

I am currently trying to add additional functionality onto an existing application, and have started using MvvmCross for the new screens, therefore I have a hybrid app on my hand right now. I want to navigate from an old screen to a new screen using ViewModel, and passing an object in memory as well. I've followed the suggestions from here:

Using Notifications on android with MvvmCross

Here is my code:

var viewModelRequest = MvxViewModelRequest<MyViewModel>.GetDefaultRequest ( );
viewModelRequest.ParameterValues = new Dictionary<string, string> ( );
viewModelRequest.ParameterValues.Add ( "myobject", JsonConvert.SerializeObject ( this.myObject, Formatting.None ) );  
var intent = Mvx.Resolve<IMvxAndroidViewModelRequestTranslator>().GetIntentFor ( viewModelRequest );    
this.StartActivity ( intent );

When I run this code, it throws a null object exception at the point where it tries to solve the IMvxAndroidViewModelRequestTranslator. I took a quick look at the mvvmcross code, and notice that the InitializeSecondary() (where InitializeViewsContainer() is called) is only called in the InitialieFromSplashScreen() method. My question is, is it because my splash screen did not inherit from MvxSplashScrennActivity, that my viewcontainers are not initialized properly? If that is the case, can I do this intialization somewhere manually?

1

1 Answers

1
votes

There are a number of methods you can use to attempt to initialize things when your app runs from within the Setup class. Reference the initial response from here where it discusses calling

protected override void InitializeLastChance(){};

Platform-specific IoC in MVVMCross

IMHO, it may be easier to just inherit or work with the built in splash class to ensure you don't run into more gotchas down the road however.