Rendering when page is hidden?

540
2
10-22-2019 03:40 PM
CalebPourchot
New Contributor III

On iOS it is a no-no to try and do any drawing when the page is not visible. On Xamarin.Forms it's really hard to catch all the times this can happen and act quickly enough. So, my question is whether the runtime is already handling this for me? 

So, for example, if the location display is on and the app gets backgrounded - if a GPS update is in the middle of being processed, will the runtime do the right thing and not try to update the location marker? Or, am I supposed to try and turn off the location marker as fast as possible when I detect the app getting backgrounded? 

If I update a graphic on the map in response to a GPS event, but the app gets backgrounded before it is drawn by the runtime, what happens?

On Forms I don't get a Page Disappearing when the app is backgrounded.

Another possible race happens if I open a new page on top of the Map View - I will get a Page Appearing of the new page before I get a Page Disappearing from the Map View page. Does that mean there is potential for a draw to occur while the map is hidden?

Not only am I curious, but I am getting untraceable crashes randomly when the map is being hidden. I get no crash logs from them so I don't even know what code is crashing (I know, not helpful to you). 

Any insight about the way I should be handling these situations would be great. 

Thanks

0 Kudos
2 Replies
dotMorten_esri
Esri Notable Contributor

I poked around a bit, and on iOS the map will stop on the following events:

 - ApplicationWillResignActive

 - ApplicationDidEnterBackground

 - WillMoveToWindow (when window is null).

The last one is most likely what will be used in your scenario. There might also be more cases (I didn't do a thorough sweep).

WRT Forms it'll stop when the Renderer gets disconnected from the view (which in turn should raise the WillMoveToWindow code). I believe this does happen in the disappearing event if I recall correctly.

0 Kudos
CalebPourchot
New Contributor III

Thanks Morten,

Just to clarify though - let's say my code was to update the geometry of a graphic in the runtime like:

someGraphic.Geometry = routeBuilder.ToGeometry();

after the runtime has handled the ApplicationDidEnterBackground notification.

Are there any scenarios where that may cause the runtime to try and draw on the map even though it is backgrounded? The MapView is the current Forms page, but the device is asleep. PageDisappearing has never been called.

It's possible that this could happen in my app (though i've gone through pains to try and prevent it) because I keep track of gps points in the background.

0 Kudos