1
votes

I just started out with learning how to use MVVMCross with Android using Xamarin Studio. I am fairly new to Android development.

I am porting an iOS app to Android and when I rotate my screen my app crashes when using fragments. I thought the problem was just me doing something wrong but when I run the sample project attached to the sample video the same thing happens. The error i get is " No default constructor found".

The Sample app I used at github : https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/Fragments

Can someone please help me out to why this is happening ?

1
I just tried both github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/… and github.com/MvvmCross/MvvmCross-Tutorials/tree/master/Fragments with the latest 3.0.14-beta2 binaries. I tried the forms, the tabs, the split screens and didn't see the error. Could you perhaps edit the question to provide more detailed information about how/when you see the error, what you are testing on, and what the full error message and stack trace is. We can try to help - but please help us by providing as good a question as possible. Thanks - Stuart
A new example that handles this is available here: github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/… - Martijn00
links are broken! - kevingoos

1 Answers

2
votes

After some digging, I "think" you are asking about how to handle rotation for a DialogFragment - I hope I've got that right.

If you do want to handle rotation in Android, then you have to:

  • provide the default constructor and you have to make use of the fragment tag
  • provide some code in the Activity.OnCreate handler in order to ensure that the DialogFragment has its ViewModel set after the rotation occurs.

I've just done this for the sample you mention in this commit - https://github.com/MvvmCross/MvvmCross-Tutorials/commit/ebe1777ec79ee2607b1b863f6b8b3911c12df53f


Note that to really fully support the Activity lifecycle - e.g. including loading/saving state when the App or Activity is "tombstoned" - then you should also go further than this - should save/restore all View and ViewModel state. MvvmCross does contain some helpers for this in the SaveState and ReloadState ViewModel methods - but even with these then fully supporting the Activity lifecycle can be quite a pain (which is why some apps don't fully support it, but instead show a "new" display instead)