I'm stucked with usage of plugin Acr.UserDialogs in android app, based on MVVMCross.
In PCL project i used IUserDialog in viewmodel constructor injection.
I have installed Acr.UserDialogs package both in PCL and in Droid project, but when i run app, it throws:
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)
Upd: Final solution to workaround this looks like:
- In PCL project App.cs add: Mvx.RegisterSingleton(() =>
- In Your first loaded activity in OnCreate
add: UserDialogs.Init(() => this);
This error is very clearly. You can't initialize it in viewModel, You can only do that in your main activity.
I'm getting a nullreferenceexception when using loading.
This happens when you run loading (or almost any dialog) from the constructor of your page or viewmodel. The view hasn't been rendered yet, therefore there is nothing to render to.
Android Initialization In your MainActivity
UserDialogs.Init(this); OR UserDialogs.Init(() => provide your own top level activity provider) OR MvvmCross - UserDialogs.Init(() => Mvx.Resolve<IMvxTopActivity>().Activity) OR Xamarin.Forms - UserDialogs.Init(() => (Activity)Forms.Context)