From 3a01b1f5baf0c2c8cbe0b727df8f9c712dcd3721 Mon Sep 17 00:00:00 2001 From: "Vaijanath Angadihiremath(VJ)" Date: Fri, 8 Apr 2016 14:54:42 -0700 Subject: [PATCH 1/2] Fix for intermittent crash when creating ExtendedExecutionSessoin to run the app in background. Now if the creation fails then we simply notify user that the creation failed. --- .../MyDriving.UWP/MyDriving.UWP.csproj | 2 +- .../Views/CurrentTripView.xaml.cs | 46 +++++++++++-------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/MobileApps/MyDriving/MyDriving.UWP/MyDriving.UWP.csproj b/src/MobileApps/MyDriving/MyDriving.UWP/MyDriving.UWP.csproj index f1e5c9c4..0ad4b6a7 100644 --- a/src/MobileApps/MyDriving/MyDriving.UWP/MyDriving.UWP.csproj +++ b/src/MobileApps/MyDriving/MyDriving.UWP/MyDriving.UWP.csproj @@ -400,7 +400,7 @@ Visual C++ 2015 Runtime for Universal Windows Platform Apps - + SQLite for Universal Windows Platform diff --git a/src/MobileApps/MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs b/src/MobileApps/MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs index 90c74ea6..a6e603d4 100644 --- a/src/MobileApps/MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs +++ b/src/MobileApps/MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs @@ -184,28 +184,38 @@ private async Task BeginExtendedExecution() ClearExtendedExecution(); - var newSession = new ExtendedExecutionSession + try { - Reason = ExtendedExecutionReason.LocationTracking, - Description = "Tracking your location" - }; - newSession.Revoked += SessionRevoked; - ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); - switch (result) - { - case ExtendedExecutionResult.Allowed: - session = newSession; - ViewModel.Geolocator.AllowsBackgroundUpdates = true; - ViewModel.StartTrackingTripCommand.Execute(null); + var newSession = new ExtendedExecutionSession + { + Reason = ExtendedExecutionReason.LocationTracking, + Description = "Tracking your location" + }; + newSession.Revoked += SessionRevoked; + ExtendedExecutionResult result = await newSession.RequestExtensionAsync(); + switch (result) + { + case ExtendedExecutionResult.Allowed: + session = newSession; + ViewModel.Geolocator.AllowsBackgroundUpdates = true; + ViewModel.StartTrackingTripCommand.Execute(null); - break; + break; - default: - Acr.UserDialogs.UserDialogs.Instance.Alert("Unable to execute app in the background.", - "Background execution denied.", "OK"); + default: + Acr.UserDialogs.UserDialogs.Instance.Alert("Unable to execute app in the background.", + "Background execution denied.", "OK"); - newSession.Dispose(); - break; + newSession.Dispose(); + break; + } + } + catch (Exception ex) + { + // Sometimes while creating ExtendedExecution session you get Resource not ready exception. + Logger.Instance.Report(ex); + Acr.UserDialogs.UserDialogs.Instance.Alert("Will not be able to execute app in the background.", + "Background execution session failed.", "OK"); } } From 218855f51d9440cd59a655f9989a64432eab40c2 Mon Sep 17 00:00:00 2001 From: "Vaijanath Angadihiremath(VJ)" Date: Fri, 8 Apr 2016 16:45:49 -0700 Subject: [PATCH 2/2] FIxing Object reference is not set to null exception from April 7 th hockey app crash analysis. --- .../MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/MobileApps/MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs b/src/MobileApps/MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs index a6e603d4..2a5636dc 100644 --- a/src/MobileApps/MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs +++ b/src/MobileApps/MyDriving/MyDriving.UWP/Views/CurrentTripView.xaml.cs @@ -381,7 +381,7 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => private async void DrawPath(BasicGeoposition basicGeoposition) { - if (!ViewModel.IsRecording || ViewModel.CurrentTrip.Points.Count == 0) + if (!ViewModel.IsRecording || ViewModel.CurrentTrip?.Points?.Count == 0) return; await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => @@ -393,8 +393,12 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Locations = new List( - ViewModel.CurrentTrip.Points.Select( + ViewModel.CurrentTrip?.Points?.Select( s => new BasicGeoposition() { Latitude = s.Latitude, Longitude = s.Longitude })); + + // If the viewmodel still has not added this point, then add it locally to the Locations collection. + if (Locations.Count == 0) + Locations.Add(basicGeoposition); } else Locations.Add(basicGeoposition);