我正在使用 MvvmCross 框架进行跨设备开发。当我在 Android 模拟器中测试我的应用程序时(我还不能在物理设备上测试它),在 LocationManager 上调用 RequestLocationUpdates 时出现 Java.Lang.IllegalArgumentException 异常。另外,我不知道它是否相关,但是当我将鼠标悬停在语句上时,我被告知 RequestLocationUpdates 是一个“未知方法”。无论是否发生异常,都会发生这种情况。
它似乎只在我第二次在我的应用程序中调用它时发生,但是在使用之间清除它的代码看起来应该可以工作
protected override void PlatformSpecificStart(MvxGeoLocationOptions options)
{
if (_locationManager != null)
throw new MvxException("You cannot start the MvxLocation service more than once");
_locationManager = (LocationManager)Context.GetSystemService(Context.LocationService);
var criteria = new Criteria() { Accuracy = options.EnableHighAccuracy ? Accuracy.Fine : Accuracy.Coarse };
var bestProvider = _locationManager.GetBestProvider(criteria, true);
_locationManager.RequestLocationUpdates(bestProvider, 5000, 2, this);
}
protected override void PlatformSpecificStop()
{
EnsureStopped();
}
private void EnsureStopped()
{
if (_locationManager != null)
{
_locationManager.RemoveUpdates(this);
_locationManager = null;
}
}
这个类继承自Java.Lang.Object,我已经验证了PlatformSpecificStart 和Stop 并在适当的时间调用(即Stop 肯定在第二次Start 之前调用)。谁能告诉我出了什么问题?