Reputation: 196
We have a UWP app, which has 3 registered background tasks, one is an app-trigerred task which keeps running in the background until failure.
The approach is to restore the last saved state which is kept within the background processor object, that has not failed until now, it works with those data kept until the last moment of background activity and returns data if the UI content is not gone yet (by swiping the app away from recent apps).
The only problem is when the main thread is gone and the app has to relaunch on activation, last instance of the app is terminated, which means the background object is gone too and we cannot restore anything.
Is there any wrong implemention which can cause this, is there any way to prevent it?
Clarification: The background task is getting user's location each 5 seconds and sending it to the server. There are no logs, but using Debug Output, I've ensured that the BGtask is running until relaunch, which it's suspended and terminated. An application trigger is fired while entering background and the task is forced to shut down while leaving background.
Thanks.
Upvotes: 4
Views: 387
Reputation: 63
Try to store the data you need to when the app is suspending using the
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
In the app.xaml.cs file. Don't you think that saving the user's position every five seconds and saving in on your databases is an invasion of their privacy. I don't know what your app is about but I don't see any good reason to know your user's position every 5s.
Upvotes: 1