MvvmCross 升级到 8.x 后,应用程序卡在 SplashScreen
Posted
技术标签:
【中文标题】MvvmCross 升级到 8.x 后,应用程序卡在 SplashScreen【英文标题】:Application get stuck at SplashScreen after MvvmCross upgrade to 8.x 【发布时间】:2021-12-08 07:21:14 【问题描述】:我将所有 MvvmCross 库从 7.1.2 升级到 8.0.0。根据 mvvmcross 文档中的“从 7 升级到 8”教程,我已经实现了必要的更改(覆盖 CreateLogProvider 和 CreateLogFactory 方法并将 iocProvider 作为参数添加到 InitializeFirstChance、InitializeLastChance、InitializeNavigationService 和 CreateApp):
public class Setup : MvxandroidSetup
protected override IMvxAndroidViewPresenter CreateViewPresenter() => new HistoryViewPresenter(ViewAssemblies);
protected override void InitializeFirstChance(IMvxIoCProvider iocProvider)
base.InitializeFirstChance(iocProvider);
//Things are done here
protected override void InitializeLastChance(IMvxIoCProvider iocProvider)
base.InitializeLastChance(iocProvider);
//Things are done here
protected override IMvxNavigationService InitializeNavigationService(IMvxIoCProvider iocProvider)
var loader = CreateViewModelLoader(iocProvider);
Mvx.IoCProvider.RegisterSingleton<IMvxViewModelLoader>(loader);
InitializeViewDispatcher(iocProvider);
var dispatcher = CreateViewDispatcher();
Mvx.IoCProvider.RegisterSingleton(dispatcher);
var navigationService = new DeepNavigationService(null, loader, dispatcher, iocProvider);
Mvx.IoCProvider.RegisterSingleton<IMvxNavigationService>(navigationService);
return navigationService;
//Another things are done here
protected override IMvxApplication CreateApp(IMvxIoCProvider iocProvider)
return new App();
protected override ILoggerProvider CreateLogProvider()
return new SerilogLoggerProvider();
protected override ILoggerFactory CreateLogFactory()
Serilog.Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.CreateLogger();
return new SerilogLoggerFactory();
我还在 Core 项目中创建了自定义应用启动并设置了此类 RegisterCustomAppStart:
public class AppStart : MvxAppStart
public AppStart(IMvxApplication application, IMvxNavigationService navigationService) : base(application, navigationService)
protected override Task NavigateToFirstViewModel(object hint = null)
return NavigationService.Navigate<StartupViewModel>();
public class App : MvxApplication
public override void Initialize()
//Services and Singletons are registered here.
RegisterCustomAppStart<AppStart>();
这是问题所在 - 当我运行应用程序时,我的应用程序卡在 SplashScreen 中。有没有人遇到过类似的问题?在以前的版本中,一切都很好。我会很感激一些建议如何解决这个问题
【问题讨论】:
不应该MvxAndroidSetup
有App
类型吗?喜欢MvxAndroidSetup<App>
?
和MvxApplication
到MvxApplication<Setup,App>
一样指定here
是的,我忘了设置,但添加后,应用程序仍然卡在 SplashScreen
我只是在创建一个新解决方案并将其与您的解决方案进行比较,所以我可能会弄错。用RegisterAppStart<StartupViewModel>();
代替RegisterCustomAppStart
怎么样?
很遗憾,还是不行,问题还是一样。我在代码行Mvx.IoCProvider.RegisterSingleton(dispatcher);
设置了断点,并意识到应用程序不会在此处停止(如果设置了断点,则上层应用程序将停止)
【参考方案1】:
我解决了这个问题 - 我换行了:
var dispatcher = CreateViewDispatcher();
为:
var dispatcher = Mvx.IoCProvider.Resolve<IMvxViewDispatcher>();
而且它有效。
【讨论】:
这对我有用,但是在调用 NavigationService.Navigate以上是关于MvvmCross 升级到 8.x 后,应用程序卡在 SplashScreen的主要内容,如果未能解决你的问题,请参考以下文章
如何使用带有 MvvmCross MvxTabsFragmentActivity 的 Android Xamarin 创建选项卡
MvvmCross Tabs 控制器包装到 UINavigation 控制器中?
Mvvmcross 8.0.2 Android MvxDialogFragment 没有用后退按钮关闭