MvvmCross with Fragments

Can anyone point me at a good tutorial on getting started with MvvmCross and Android Fragments.

I do have a working example using a custom MvxAndroidViewPresenter, but I'm having trouble understanding what I'm meant to do about maintaining state on screen rotations - i.e. which fragment is in view and back stack etc.

Thanks

Matt

Posts

  • CheesebaronCheesebaron DKInsider, University mod
    edited June 2015

    We are working on a new set of libraries supporting stuff from the Android Support packages. It can be found here: https://github.com/MvvmCross/MvvmCross-AndroidSupport

    There is a pull request with a sample showing all the stuff in use including Fragments: https://github.com/MvvmCross/MvvmCross-AndroidSupport/pull/31

    All this stuff can be found as nuget packages as well, you need to enable searching for prereleases in your NuGet package manager.

  • codenutzcodenutz GBMember

    Thanks, I'll take a look

  • CheesebaronCheesebaron DKInsider, University mod

    If you need more realtime help, try joining the #mvvmcross room on jabbr.net

  • Martijn00Martijn00 NLInsider, University ✭✭✭

    The sample is merged in now, and some more fixes are included, see here: https://github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/Samples

    The Jabbr Room Cheesebaron mentions is here: https://jabbr.net/#/rooms/mvvmcross

  • codenutzcodenutz GBMember

    Thanks @Cheesebaron and @Martijn00 - I've been working through that sample and am starting to get somewhere!

    One question - the example has ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize which avoids the whole screen rotation / saving restoring state issue somewhat, but this is generally not advised. But if I remove this, my fragments are reset on screen rotation etc.

    How am I meant to handle this?

  • codenutzcodenutz GBMember
    edited July 2015

    Looks like the sample on Github is using a pretty different version of the library to the nuget package. The sample uses MvxCachingFragmentActivity and stuff around which doesn't exist in the current nuget package.

    I replicated those classes into my own project which has gotten me some way into implementing it, but I've still not a basic sample working with the nav drawer etc.

    Everything seemed to be going fine until I added the call into AttachBaseContext, at which point the app just bombs out at base.OnCreate(bundle) with an object reference not set exception. It does run without that override, but I cannot get the nav drawer working without it.

    The error is something around here:

    UNHANDLED EXCEPTION:
    System.NullReferenceException: Object reference not set to an instance of an object
    at Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.Binding.BindingContext.IMvxBindingContextStack`1<Cirrious.MvvmCross.Binding.Droid.BindingContext.IMvxAndroidBindingContext>> () <0x00060>
    I/MonoDroid( 7801): at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current<Cirrious.MvvmCross.Binding.Droid.BindingContext.IMvxAndroidBindingContext> () <0x00033>
    I/MonoDroid( 7801): at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current () <IL 0x00000, 0x00023>
    I/MonoDroid( 7801): at Cirrious.MvvmCross.Binding.Droid.Views.MvxLayoutInflater.Inflate (int,Android.Views.ViewGroup,bool) <IL 0x00008, 0x00057>
    

    I gather this is something resolved in the source code but has not yet made it into the nuget package.

    UPDATE: This comment seems to have appeared days after I originally posted it and as such I have already worked out what was causing the exception - i.e. something related to the splash screen not being set correctly

    Matt

  • codenutzcodenutz GBMember
    edited July 2015

    Looks like the sample on Github is using a pretty different version of the library to the nuget package. The sample uses MvxCachingFragmentActivity and stuff around which doesn't exist in the current nuget package.

    I replicated those classes into my own project which has gotten me some way into implementing it, but I've still not a basic sample working with the nav drawer etc.

    Everything seemed to be going fine until I added the call into AttachBaseContext, at which point the app just bombs out at base.OnCreate(bundle) with an object reference not set exception. It does run without that override, but I cannot get the nav drawer working without it.

    The error is something around here:

    UNHANDLED EXCEPTION:
    System.NullReferenceException: Object reference not set to an instance of an object
    at Cirrious.CrossCore.Mvx.Resolve<Cirrious.MvvmCross.Binding.BindingContext.IMvxBindingContextStack`1<Cirrious.MvvmCross.Binding.Droid.BindingContext.IMvxAndroidBindingContext>> () <0x00060>
    I/MonoDroid( 7801): at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current<Cirrious.MvvmCross.Binding.Droid.BindingContext.IMvxAndroidBindingContext> () <0x00033>
    I/MonoDroid( 7801): at Cirrious.MvvmCross.Binding.Droid.BindingContext.MvxAndroidBindingContextHelpers.Current ()
    I/MonoDroid( 7801): at Cirrious.MvvmCross.Binding.Droid.Views.MvxLayoutInflater.Inflate (int,Android.Views.ViewGroup,bool)

    I gather this is something resolved in the source code but has not yet made it into the nuget package.

    All in all a very frustrating evening!!

    Matt

  • JeremyKolbJeremyKolb USMember ✭✭✭

    Ah this was my fault but it should be fixed in the latest. Are you good now?

  • codenutzcodenutz GBMember

    I think so - I have a sample running now with a few complications. Still not sure I'm getting this 100% right to be honest thought!

Sign In or Register to comment.