Question

There are lots of questions on SO about updating the UI from a background thread. This question is a little different- I'm wondering how I can update the UI when my app is actually in the background. Here's my issue:

I've tried both MapKit and Google's mapping SDKs. I've found that I prefer Google's (far more simpler and concise to manage; MapKit involves a significant amount of boilerplate code, not to mention MapKit's memory usage in iOS 6 has significant issues). Yet I've found that if, for example, I am recording a user's path, creating an overlay/polyline with the trail, when the app goes to the background, there is often a significant delay or frozen period when the app returns to the foreground. When the app goes to the background, it seems that the polylines on the screen are no longer updated, and when the app returns to the foreground it has to 'catch up,' which can sometimes take a while. I have occasionally had crashes due to the app taking too long to resume.

So my question is: How can I force the UI to be updated even when the app is in the background so I can eliminate this 'catch up' period when my app is resumed?

I can add any code/explanation for anything that is unclear. Thanks!

Was it helpful?

Solution

You can't and shouldn't update the UI while in the background. Your best bet would be to set a threshold on the background data recording. While within the threshold, "catch-up" the UI when entering the foreground. When outside the threshold, reset the UI on entering foreground. When the threshold is crossed, data should be maintained to be enough for just a reset (not the whole history). Pre-threshold, maintain it all.

App Flow:

  1. App Launch
  2. Collect and Display Data on Overlay
  3. App Background
  4. Continue Collecting Data

Then onForeground:

 if (appForegroundBeforeTooMuchData) {
       //Update Overlay
 } else { 
       //We have too much data to update the overlay smoothly, store the data and start a *new session* on foreground
       //Behave as if user just started the app
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top