MVVMCROSS片段试样与旋转工作 [英] MVVMCROSS Fragment sample not working with rotation

查看:177
本文介绍了MVVMCROSS片段试样与旋转工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始了学习如何使用Xamarin Studio来使用MVVMCross与Android。我是相当新的Andr​​oid开发。

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

我移植iOS应用到Android,当我转动我的屏幕我的应用程序崩溃使用整理碎片时。我觉得这个问题只有我做错了什么,但是当我运行附着在样本视频同样的事情发生在示例项目。我得到的错误是没有找到默认的构造函数。

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".

示例应用程序在我使用GitHub的: https://github.com/ MvvmCross / MvvmCross-教程/树/主/片段

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 ?

推荐答案

一些挖后,我想你是问如何处理旋转 DialogFragment - 我希望我有这个权利。

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

如果你想在Android中来处理旋转,那么你必须:

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


  • 提供默认的构造函数,你必须利用片段标记

  • 提供的 Activity.OnCreate 处理一些code,以确保 DialogFragment 有其视图模型发生旋转后设置。

  • 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.

我刚刚做了这个给你这个承诺提样本 - <一个href=\"https://github.com/MvvmCross/MvvmCross-Tutorials/commit/ebe1777ec79ee2607b1b863f6b8b3911c12df53f\" rel=\"nofollow\">https://github.com/MvvmCross/MvvmCross-Tutorials/commit/ebe1777ec79ee2607b1b863f6b8b3911c12df53f

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

请注意,要真正完全支持活动生命周期 - 例如包括加载/保存状态时,应用程序或活动是墓碑 - 那么你也应该更进一步比这 - 应该保存/恢复所有视图和视图模型状态。 MvvmCross确实包含了一些助手本在即时存档 ReloadState 视图模型方法 - 但即使这些话完全支持活动生命周期可以是一个相当痛苦(这就是为什么一些应用程序不完全支持它,而是展现出新,而不是显示)

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)

这篇关于MVVMCROSS片段试样与旋转工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆