【问题标题】:Xamarin Android - On relase issueXamarin Android - 关于发布问题
【发布时间】:2017-07-18 15:38:48
【问题描述】:

我创建了位置跟踪应用程序。今天我还添加了地理围栏功能。 I 是一个简单的单例类,当地理位置在给定坐标附近时会引发事件。

当我手动引发事件时,它会按预期工作。但是,当我在达到坐标时设置为释放模式时,它会停止应用程序。我里面有错误日志,写的是: java.lang.reflect.InvocationTargetException

我正在使用 MVVMCross 库。我的视图模型附加到地理围栏服务类女巫回调。当用户到达坐标时,应该调用回调。正如我在调试中所说,它正在工作。

以下代码示例:

public class GeofenceService : IGeofenceService
    {
      //...
      public event EventHandler<GeofenceStatusChangedEventArgs> StatusChanged;
      //..
    }


 public abstract class GeofenceViewModel : BaseViewModel
    {
       protected IGeofenceService GeofenceService { get; }

       protected virtual void StartMonitoring(AddressModel address, MonitoringRadius radius)
        {
            MonitoredAddress = address;
            GeofenceService.StartMonitoring(new Location(address.Id, address.Latitude, address.Longitude), radius, GeofenceExpectation);
            GeofenceService.Subscribe(this, OnStatusChanged);
        }

 protected void OnStatusChanged(object sender, GeofenceStatusChangedEventArgs e)
        {
           //...
        }
    }

有没有办法获得真正的异常?

【问题讨论】:

    标签: c# android exception xamarin


    【解决方案1】:

    当然,在您的 : Application 类初始化中添加 Exeptions 委托

    AndroidEnvironment.UnhandledExceptionRaiser += (object sender, RaiseThrowableEventArgs e) => {
        //Save exeption to file (e.Exception.ToString ())
    };
    

    但根据我的经验,我建议您比较调试和发布配置(选项),可能有一些设置不匹配并导致崩溃。

    【讨论】:

    • 这行代码节省了我很多时间。非常感谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多