Skip to content

Commit

Permalink
Fix for intermittent crash when creating ExtendedExecutionSessoin to …
Browse files Browse the repository at this point in the history
…run the app in background.

Now if the creation fails then we simply notify user that the creation failed.
  • Loading branch information
VaijanathB committed Apr 8, 2016
1 parent 70a321a commit 3a01b1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
<SDKReference Include="Microsoft.VCLibs, Version=14.0">
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
</SDKReference>
<SDKReference Include="SQLite.UWP.2015, Version=3.11.1">
<SDKReference Include="SQLite.UWP.2015, Version=3.12.0">
<Name>SQLite for Universal Windows Platform</Name>
</SDKReference>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down

0 comments on commit 3a01b1f

Please sign in to comment.