Mvvmcross Android - Rotating Fragment View During Viewmodel Population
I'm having a problem when I try to manually re hydrate fragment viewmodels while rotating. Everything seems to work fine when I rotate a fragment once my viewmodel has been populat
Solution 1:
I think I may have an initial solution to the problem I was having. I was using the following to run code post-.
TypedViewModel.PopulateAndRun(() =>
{
DoSomething();
});
The problem seemed to be that this action was only called once and that possibly the action which was being fired was for the old view and not the new view.
I tried adding the following code in addition to the code above, and it worked
TypedViewModel.OnPopulated += ()
{
DoSomething();
});
Solution 2:
One way to approach this problem is to instruct Android not to re-create the activity when configuration changes. Make sure you have "ConfigurationChanges" specificed in the activity attribute and you override OnConfigurationChanged.
[Activity( Label = "Sample", ConfigurationChanges = global::Android.Content.PM.ConfigChanges.Orientation | global::Android.Content.PM.ConfigChanges.ScreenSize | global::Android.Content.PM.ConfigChanges.KeyboardHidden )] public class SampleActivity : MvxFragmentActivity { //... public override void OnConfigurationChanged(global::Android.Content.Res.Configuration newConfig) { base.OnConfigurationChanged(newConfig); } }
Post a Comment for "Mvvmcross Android - Rotating Fragment View During Viewmodel Population"