public class App : MvxApplication{ public overrIDe voID Initialize() { MPS.Applicationname = Settings.Applicationname; EventLog.Applicationname = Settings.Applicationname; Blobcache.Applicationname = Settings.Applicationname; CreatableTypes() .EndingWith("Service") .AsInterfaces() .RegisterasLazySingleton(); CreatableTypes() .EndingWith("Singleton") .AsInterfaces() .RegisterasSingleton(); //RegisterappStart(new CustomAppStart()); //RegisterNavigationServiceAppStart<Loginviewmodel>(); RegisterappStart<Loginviewmodel>(); }}
这是非常基本的.我已经转换为新的导航系统因此RegisterNavigationServiceAppStart.那将不再解决,所以我回到了直接的RegisterappStart.启动画面出现然后停止.如果重要,splashscreen.cs如下:
[Activity( Label = "@string/Applicationname",MainLauncher = true,Icon = "@drawable/icon",theme = "@style/theme.Splash",NoHistory = true)] //,ScreenorIEntation = ScreenorIEntation.Landscape)]public class SplashScreen : MvxSplashScreenActivity{ public SplashScreen() : base(Resource.Layout.SplashScreen) { }}
这很香草,但我知道事情已经发生了变化.我的setup.cs如下:
public class Setup : MvxAndroIDSetup{ //public Setup(Context applicationContext) // : base(applicationContext) //{ //} protected overrIDe IMvxApplication CreateApp() { return new App(); } //protected overrIDe IMvxTrace CreateDeBUGTrace() //{ // return new DeBUGTrace(); //} protected overrIDe IMvxAndroIDVIEwPresenter CreateVIEwPresenter() { return new MvxAppCompatVIEwPresenter(AndroIDVIEwAssemblIEs); } protected overrIDe voID FillValueConverters(IMvxValueConverterRegistry registry) { base.FillValueConverters(registry); registry.AddOrOverwrite("DatetoStringConverter",new DatetoStringConverter()); registry.AddOrOverwrite("floatToStringConverter",new floatToStringConverter()); registry.AddOrOverwrite("DecimalToStringConverter",new DecimalToStringConverter()); registry.AddOrOverwrite("BoolToVIEwStatesConverter",new BoolToVIEwStatesValueConverter()); registry.AddOrOverwrite("ShipmentToOriginConverter",new ShipmentToOriginConverter()); registry.AddOrOverwrite("ShipmentToDestinationConverter",new ShipmentToDestinationConverter()); //registry.AddOrOverwrite("Customname2",new AnotherVerySpecialValueConverter("Summer")); } protected overrIDe voID FillTargetFactorIEs(MvvmCross.Binding.Bindings.Target.Construction.IMvxTargetBindingFactoryRegistry registry) { base.FillTargetFactorIEs(registry); registry.RegisterCustomBindingFactory<EditText>("FocusText",textVIEw => new MvxEditTextFocusBinding(textVIEw)); registry.RegisterCustomBindingFactory<TextVIEw>("FocusChange",textVIEw => new MvxTextVIEwFocusChangeBinding(textVIEw)); //registry.RegisterCustomBindingFactory<MvxSpinner>("ItemSelected",// spinner => new MvxSpinnerItemSelectedBinding(spinner)); } protected overrIDe IEnumerable<Assembly> AndroIDVIEwAssemblIEs => new List<Assembly>(base.AndroIDVIEwAssemblIEs) { typeof(MvvmCross.DroID.Support.V7.RecyclerVIEw.MvxRecyclerVIEw).Assembly };}
我对它做的唯一改变是删除构造函数.根据6.0版的文档,构造函数不再有参数,所以我没有理由调用它.有人可以帮忙吗?
**更新**
我添加了一个MainApplication.cs,如下所示:
[Application]public class MainApplication : MvxAppCompatApplication<Setup,App>{ public MainApplication(IntPtr javaReference,JniHandleOwnership transfer) : base(javaReference,transfer) { }}
这让我超越了启动画面,但挂起了Loginviewmodel的Initialize.
*日志*
也许这会有所帮助.以下是事件日志条目:
2018-04-17 12:17:06 [TRACE] (MvvmCross.Core.MvxSetup) Setup: Primary start2018-04-17 12:17:06 [TRACE] (MvvmCross.Core.MvxSetup) Setup: FirstChance start2018-04-17 12:17:06 [TRACE] (MvvmCross.Core.MvxSetup) Setup: PlatformServices start2018-04-17 12:17:06 [TRACE] (MvvmCross.Core.MvxSetup) Setup: MvvmCross settings start2018-04-17 12:17:06 [TRACE] (MvvmCross.Core.MvxSetup) Setup: Singleton Cache start2018-04-17 12:17:06 [TRACE] (MvvmCross.Core.MvxSetup) Setup: VIEwdispatcher start2018-04-17 12:17:06 [TRACE] (MvvmCross.Core.MvxSetup) Setup: bootstrap actions2018-04-17 12:17:07 [TRACE] (MvvmCross.Logging.MvxLog) No vIEw model type finder available - assuming we are looking for a splash screen - returning null2018-04-17 12:17:07 [TRACE] (MvvmCross.Core.MvxSetup) Setup: StringToTypeParser start2018-04-17 12:17:07 [TRACE] (MvvmCross.Core.MvxSetup) Setup: CommandHelper start2018-04-17 12:17:07 [TRACE] (MvvmCross.Core.MvxSetup) Setup: PluginManagerFramework start2018-04-17 12:17:07 [TRACE] (MvvmCross.Core.MvxSetup) Setup: Create App2018-04-17 12:17:07 [TRACE] (MvvmCross.Core.MvxSetup) Setup: NavigationService2018-04-17 12:17:07 [TRACE] (MvvmCross.Core.MvxSetup) Setup: Load navigation routes2018-04-17 12:17:07 [TRACE] (MvvmCross.Core.MvxSetup) Setup: App start2018-04-17 12:17:07 [TRACE] (MvvmCross.Core.MvxSetup) Setup: Application Initialize - On background thread2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: viewmodelTypeFinder start2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: VIEwsContainer start2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: VIEws start2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: CommandCollectionBuilder start2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: NavigationSerializer start2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: InpcInterception start2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: InpcInterception start2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: LastChance start2018-04-17 12:17:08 [TRACE] (MvvmCross.Core.MvxSetup) Setup: Secondary end2018-04-17 12:17:08 [TRACE] (MvvmCross.Logging.MvxLog) AppStart: Application Startup - On UI thread
我进一步追踪它.它挂在视图模型中的Initialize()上.我创建了一个测试来演示:
public class Firstviewmodel : Mvxviewmodel{ public Firstviewmodel() { Task.Run(async () => { var l = await ListDataSource.GetLocations(); var m = l; }); } public async overrIDe Task Initialize() { await base.Initialize(); var l = await ListDataSource.GetLocations(); var m = l; }}
如果我在两个var m = l上设置一个断点,它将到达构造函数中的断点,但永远不会到达Initialize中的断点. GetLocations是:
public async static Task<LocationList> GetLocations() { ListServiceClIEnt clIEnt = NewClIEnt(); LocationList ret = null; bool TryCache = false; try { //ret = await clIEnt.GetLocationListAsync(); ret = await Task<LocationList>.Factory.FromAsync((asyncCallback,asyncState) => clIEnt.BeginGetLocationList(asyncCallback,asyncState),(asyncResult) => clIEnt.EndGetLocationList(asyncResult),null); clIEnt.Close(); await Blobcache.LocalMachine.InsertObject("Locations",ret,DateTimeOffset.Now.AddDays(Settings.CacheDays)); } catch (TimeoutException ex) { clIEnt.Abort(); EventLog.Error(ex.ToString()); TryCache = true; } catch (CommunicationException ex) { clIEnt.Abort(); EventLog.Error(ex.ToString()); TryCache = true; } catch (Exception ex) { EventLog.Error(ex.ToString()); TryCache = true; } if (TryCache) { try { ret = await Blobcache.LocalMachine.Getobject<LocationList>("Locations"); } catch (KeyNotFoundException) { ret = null; } } return ret; }
如果在ClIEnt.Close()上设置一个断点,如果从构造函数调用它,它将到达那里,但如果从Initialize调用则不会.
解决方法 我的问题是双重的.首先,当您使用AndroID升级到6.0版时,您现在必须包含MainApplication.cs,如下所示:[Application]public class MainApplication : MvxAppCompatApplication<Setup,transfer) { }}
如果没有这个,你将被困在SplashScreen上.其次,您需要知道您显示的第一个viewmodel中的Initialize必须是同步的.正如@Ale_lipa所提到的,一位MvvmCross作者撰写了一篇博客文章,解释了为什么会这样做以及如何处理它.
https://nicksnettravels.builttoroam.com/post/2018/04/19/MvvmCross-Initialize-method-on-the-first-view-model.aspx
简而言之,如果您使用的是SplashScreen,并且您确实需要将第一个viewmodel的Initialize作为Async,则可以按如下方式添加CustomAppStart:
public class CustomMvxAppStart<Tviewmodel> : MvxAppStart<Tviewmodel> where Tviewmodel : IMvxviewmodel{ public CustomMvxAppStart(IMvxApplication application,IMvxNavigationService navigationService) : base(application,navigationService) { } protected overrIDe voID NavigatetoFirstviewmodel(object hint) { NavigationService.Navigate<Tviewmodel>(); }}
在你的App.cs中,替换你的:
RegisterappStart<Firstviewmodel>();
有:
RegisterCustomAppStart<CustomMvxAppStart<Firstviewmodel>>();
这将允许您的第一个Initialize异步.我只确定它适用于AndroID,并且只有在使用SplashScreen时才有效.
总结以上是内存溢出为你收集整理的xamarin.android – 升级到6.0版后,MvvmCross App无法启动全部内容,希望文章能够帮你解决xamarin.android – 升级到6.0版后,MvvmCross App无法启动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)