问题
After upgrading MvvmCross from 5.1 to 5.2 , my CustomAndroidPresenter.cs is throwing a build error. What is causing this?
CustomAndroidPresenter.cs:
namespace TestPrjDroid
{
public class CustomAndroidPresenter : MvxAndroidViewPresenter
{
public override void Show(MvxViewModelRequest request)
{
if (request != null && request.PresentationValues != null)
{
if (request.PresentationValues.ContainsKey("MyCustomFlag"))
{
// Get intent from request and set flags to clear backstack.
var intent = base.CreateIntentForRequest(request);
intent.AddFlags(ActivityFlags.ClearTask | ActivityFlags.ClearTop | ActivityFlags.NewTask);
base.Show(intent);
return;
}
}
base.Show(request);
}
}
}
Error:
There is no argument given that corresponds to the required formal parameter 'androidViewAssemblies' of 'MvxAndroidViewPresenter.MvxAndroidViewPresenter(IEnumerable)'
Argument 1: cannot convert from 'Android.Content.Intent' to 'MvvmCross.Core.ViewModels.MvxViewModelRequest'
回答1:
You need to add a constructor for MvxAndroidViewPresenter(IEnumerable)
:
public class CustomAndroidPresenter : MvxAndroidViewPresenter
{
public CustomAndroidPresenter(IEnumerable<Assembly> androidViewAssemblies) : base(androidViewAssemblies)
{
}
public override void Show(MvxViewModelRequest request)
{
if (request != null && request.PresentationValues != null)
{
if (request.PresentationValues.ContainsKey("MyCustomFlag"))
{
// Get intent from request and set flags to clear backstack.
var intent = base.CreateIntentForRequest(request);
intent.AddFlags(ActivityFlags.ClearTask | ActivityFlags.ClearTop | ActivityFlags.NewTask);
base.ShowIntent(intent);
return;
}
}
base.Show(request);
}
}
来源:https://stackoverflow.com/questions/46280219/upgrading-mvvmcross-to-5-2-shows-error-on-customandroidpresenter