每当我旋转设备时,我都会崩溃。我正在使用MvvmCross 4.0.0.beta-3,以下是我的应用设置:
Setup.cs
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var customPresenter = new MvxFragmentsPresenter();
Mvx.RegisterSingleton<IMvxFragmentsPresenter>(customPresenter);
return customPresenter;
}
ShellPage.cs
public abstract class ActivityBase<TViewModel> : MvxCachingFragmentCompatActivity<TViewModel>
where TViewModel : MvxViewModel
{
.
.
.
}
HomePage.cs
[Activity(
Label = "Home",
MainLauncher = true,
LaunchMode = LaunchMode.SingleTop)]
public class ShellPage : ActivityBase<ShellPageViewModel>, IMvxFragmentHost
{
.
.
.
public void RegisterFragment<TFragment, TViewModel>(string tag, Bundle args)
where TFragment : IMvxFragmentView
where TViewModel : IMvxViewModel
{
var customPresenter = Mvx.Resolve<IMvxFragmentsPresenter>();
customPresenter.RegisterViewModelAtHost<TViewModel>(this);
RegisterFragment<TFragment, TViewModel>(tag);
}
public bool Show(MvxViewModelRequest request, Bundle bundle)
{
if (request.ViewModelType == typeof(MenuContentViewModel))
{
ShowFragment(request.ViewModelType.Name, Resource.Id.navigation_frame, bundle);
return true;
}
else
{
ShowFragment(request.ViewModelType.Name, Resource.Id.content_frame, bundle, true);
return true;
}
}
.
.
.
}
MainFragment.cs
[MvxOwnedViewModelFragment]
[Register("xxxxx.android.fragments.MainFragment")]
public class MainFragment : MvxFragment<MainFragmentViewModel>
{
.
.
.
}
我发布了上面的代码,表明我使用MvxCachingFragmentCompatActivity作为基本活动,IMvxFragmentHost,因为我的ShellPage是唯一一个使用NavigationDrawer交换片段进/出的页面,以及我的片段上有[MvxOwnedViewModelFragment]属性。
当我旋转时,我收到以下错误:
10-20 12:10:02.470 I/MonoDroid( 6108): UNHANDLED EXCEPTION:
10-20 12:10:02.471 I/MonoDroid( 6108): System.NullReferenceException: Object reference not set to an instance of an object
10-20 12:10:02.471 I/MonoDroid( 6108): at Cirrious.MvvmCross.Droid.Support.AppCompat.MvxCachingFragmentCompatActivity.RestoreLookupFromSleep ()
10-20 12:10:02.471 I/MonoDroid( 6108): at Cirrious.MvvmCross.Droid.Support.AppCompat.MvxCachingFragmentCompatActivity.OnPostCreate (Android.OS.Bundle)
有什么想法吗?
谢谢!
答案 0 :(得分:3)
今天发布的新MvvmCross beta4有多个修复方法。样本也进行了大量更新:https://github.com/MvvmCross/MvvmCross-AndroidSupport/tree/master/Samples