I am trying to implement a partial update for my watchface. When I enter OnUpdate(), at the start of every minute I want to do a bunch of calculations that are fairly CPU intensive. In between that minute to the next minute I don't want to do anything and just keep the screen the same as before. Therefore I need a way to immediately exit OnUpdate(). I have implemented this by checking if the current clock time minute has changed, and if not I return immediately from OnUpdate() without calling dc.clear or View.onUpdate(dc). Therefore it shouldn't redraw any of the layout and it should keep things the same, right? That way if the user looks at their watch and triggers updates every second, OnUpdate() whill be called but it won't redraw anything, and it will just exit early and do nothing essentially.
Everything works in the simulator. The problem I'm having is that the actual behavior on a device differs. I have a 945 and a vivoactive 4 and they do different things and I don't know why. On the 945, the above process works correctly just as I described. On the VA4 however, my screen is cleared to black every time the early exit occurs. To make the matter worse, it appears OnUpdate() is always called twice when my face loads. For example if I scroll through the widget loop and then return to my watch face, I see everything draw correctly, and then less than a second later the screen flashes black, as though two OnUpdate() calls were made in rapid succession.
I'm not sure why the screen is getting cleared because I'm definitely not doing that myself. Does entering OnUpdate() always cause a screen draw/clear for some reason on a VA4 but not on a 945? I'm really confused about how to fix this and ensure it works on all devices.
I tried this code to see if had to do with transition animations. I added a 5 second delay before allowing the early return.
// Only allow early return 5 seconds after face has loaded if( layoutTime != null && ( now.value() - layoutTime.value() ) > 5 ) { if( isClosing || ( clockTime.min == lastMin && !newDataReceived ) ) { return; } } else { //It's a new minute or still less than 5 seconds after layout occurred //Do stuff }
What I see is that the app draws correctly for the first 5 seconds after layout, and then immediately the screen goes black on the VA4 the first time it hits the return statement. Again this doesn't happen on the 945 and it continues to draw correctly.