First of all, thanks for example.
But I have a problem integrating your example with other packages that require initialization on each platform (in this case Android). For example, I installed the Acr.UserDialogs package version 6.4.1.
The only thing I modify is the main activity after calling based on the super class I initialize the plugin.
namespace MvxForms.Droid
{
[Activity(Label = "MvxForms.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : MvxFormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
UserDialogs.Init(this);
PullToRefreshLayoutRenderer.Init();
XFGloss.Droid.Library.Init(this, bundle);
//Initializing FFImageLoading
CachedImageRenderer.Init();
}
}
}
namespace MvxForms.Core
{
public class CoreApp : MvvmCross.Core.ViewModels.MvxApplication
{
public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();
Mvx.RegisterSingleton<IUserDialogs>(() => UserDialogs.Instance);
RegisterAppStart<ViewModels.MvxFormsViewModel>();
}
}
}
Modify your example ViewModel to request the injection of the service.
namespace MvxForms.Core.ViewModels
{
public class MvxFormsViewModel : MvxViewModel
{
protected readonly IUserDialogs _userDialogs;
public MvxFormsViewModel(IUserDialogs userDialogs)
{
_userDialogs = userDialogs;
}
public override Task Initialize()
{
//TODO: Add starting logic here
return base.Initialize();
}
public IMvxCommand ResetTextCommand => new MvxCommand(ResetText);
private void ResetText()
{
Text = "Hello MvvmCross";
}
private string _text = "Hello MvvmCross";
public string Text
{
get { return _text; }
set { SetProperty(ref _text, value); }
}
}
}
mvx:Warning: 1.39 Exception masked MvxException: Failed to construct and initialize ViewModel for type MvxForms.Core.ViewModels.MvxFormsViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState, MvvmCross.Core.ViewModels.IMvxViewModelLocator viewModelLocator) [0x00020] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxViewModelLoader.cs:73
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x00020] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxViewModelLoader.cs:59
at MvvmCross.Forms.Presenters.MvxPresenterHelpers.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x00017] in D:\git\MvvmCross\MvvmCross-Forms\MvvmCross.Forms\Presenters\MvxPresenterHelpers.cs:25
at MvvmCross.Forms.Presenters.MvxFormsPagePresenter.TryShowPage (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x0000c] in D:\git\MvvmCross\MvvmCross-Forms\MvvmCross.Forms\Presenters\MvxFormsPagePresenter.cs:88
at MvvmCross.Forms.Presenters.MvxFormsPagePresenter.Show (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x00000] in D:\git\MvvmCross\MvvmCross-Forms\MvvmCross.Forms\Presenters\MvxFormsPagePresenter.cs:60
at MvvmCross.Droid.Views.MvxAndroidViewDispatcher+<>c__DisplayClass2_0.<ShowViewModel>b__0 () [0x00000] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxAndroidViewDispatcher.cs:26
at MvvmCross.Droid.Views.MvxAndroidMainThreadDispatcher.RequestMainThreadAction (System.Action action, System.Boolean maskExceptions) [0x00020] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxAndroidMainThreadDispatcher.cs:20
at MvvmCross.Droid.Views.MvxAndroidViewDispatcher.ShowViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x00014] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxAndroidViewDispatcher.cs:26
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModelImpl (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle) [0x00023] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxNavigatingObject.cs:117
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModel (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle) [0x00000] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxNavigatingObject.cs:109
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModel[TViewModel] (MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle) [0x00000] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxNavigatingObject.cs:81
at MvvmCross.Core.ViewModels.MvxAppStart`1[TViewModel].Start (System.Object hint) [0x00013] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxAppStart.cs:22
at MvvmCross.Droid.Views.MvxSplashScreenActivity.TriggerFirstNavigate () [0x00006] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxSplashScreenActivity.cs:88
at MvxForms.Droid.SplashScreen.TriggerFirstNavigate () [0x00012] in /Users/BISITE/Projects/MvxForms-master/MvxForms.Droid/SplashScreen.cs:24
at MvvmCross.Droid.Views.MvxSplashScreenActivity.InitializationComplete () [0x00009] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxSplashScreenActivity.cs:82
at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.<InitializeFromSplashScreen>b__7_1 () [0x00000] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Platform\MvxAndroidSetupSingleton.cs:100
at MvvmCross.Platform.Core.MvxMainThreadDispatcher.ExceptionMaskedAction (System.Action action) [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Core\MvxMainThreadDispatcher.cs:21
InnerException was MvxException: Problem creating viewModel of type MvxFormsViewModel
at MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterValues, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x0000f] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxDefaultViewModelLocator.cs:37
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState, MvvmCross.Core.ViewModels.IMvxViewModelLocator viewModelLocator) [0x0000e] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxViewModelLoader.cs:69
InnerException was ArgumentException: In android, you must call UserDialogs.Init(Activity) from your first activity OR UserDialogs.Init(App) from your custom application OR provide a factory function to get the current top activity via UserDialogs.Init(() => supply top activity)
at Acr.UserDialogs.UserDialogs+<>c.<.cctor>b__8_0 () [0x00000] in C:\dev\acr\userdialogs\src\Acr.UserDialogs.Shared\UserDialogs.cs:19
at System.Lazy`1[T].CreateValue () [0x00081] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Lazy`1[T].LazyInitValue () [0x00080] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Lazy`1[T].get_Value () [0x0003a] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at Acr.UserDialogs.UserDialogs.get_Instance () [0x00000] in C:\dev\acr\userdialogs\src\Acr.UserDialogs.Shared\UserDialogs.cs:69
at MvxForms.Core.CoreApp+<>c.<Initialize>b__0_0 () [0x00000] in /Users/BISITE/Projects/MvxForms-master/MvxForms.Core/CoreApp.cs:16
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer+<>c__DisplayClass33_0`1[TInterface].<RegisterSingleton>b__0 () [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:290
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer+ConstructingSingletonResolver.Resolve () [0x00028] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:136
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, MvvmCross.Platform.IoC.MvxSimpleIoCContainer+IResolver resolver, System.Object& resolved) [0x00041] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:445
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Nullable`1[T] requiredResolverType, System.Object& resolved) [0x0002e] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:403
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:385
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.TryResolve (System.Type type, System.Object& resolved) [0x00011] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:180
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00015] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:494
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0002c] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:312
at MvvmCross.Platform.Mvx.IocConstruct (System.Type t) [0x00006] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Mvx.cs:169
at MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterValues, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x00000] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxDefaultViewModelLocator.cs:33
Could you give me some tips on how I can solve this problem? Thank you very much in advance.