Ok. I’m back. Here’s why I am still on shaky ground… I was trying to understand the native.setActivityIndicator() and was thrown off by a comment by Brent in a spinner thread… He said
Just remember that you can’t start and stop the indicatorin the same code chunk… you need to start it when the process begins, and then queue a callback or other function to stop it when the process is complete.
This was a moment of clarity, I thought I understood it but I still wanted to challenge it. Challenge was to simplify the ActivityIndicator sample to its barebones and then write it in a non-event driven , sequential manner. I was hoping to understand this more and along the way I managed to confuse myself some more…
Here is barebones Activity Indicator code. This will just put up the background image and then count to 5 while showing the ActivityIndicator and then take it away.
local numSeconds = 5 local counter = display.newText( tostring( numSeconds ), 0, 0, system.systemFontBold, 36 ) function counter:timer( event ) numSeconds = numSeconds - 1 counter.text = tostring( numSeconds ) if 0 == numSeconds then native.setActivityIndicator( false ); end end timer.performWithDelay( 1000, counter, numSeconds ) native.setActivityIndicator( true ); display.newImage( "aquariumbackgroundIPhone.jpg", 0, 0 )
Then I wrote the following. I put in specific print lines in between to prove sequential execution…
print ("line 1", os.time() ) local numSeconds = 5 print ("line 2", os.time() ) display.newImage( "aquariumbackgroundIPhone.jpg", 0, 0 ) print ("line 3", os.time() ) native.setActivityIndicator( true ); print ("line 4", os.time() ) local counter = display.newText( tostring( numSeconds ), 0, 0, system.systemFontBold, 36 ) print ("line 5", os.time() ) local markTime = os.time() print ("line 6", os.time() ) local timePassed = os.time() - markTime print ("line 7", os.time() ) while timePassed \< 5 do timePassed = os.time() - markTime counter = display.newText( tostring( timePassed ), 0, 0, system.systemFontBold, 36 ) end print ("line 8", os.time() ) native.setActivityIndicator( false ); print ("line 9", os.time() )
So there I was trying to prove it can be done. I was wrong. The background image did not come through all the way until the end of the countdown of 5 seconds. The call to put it up is right at the top of this code. I see
print (“line 2”, os.time() )
print (“line 3”, os.time() )
In the terminal but the call to display the background image which is right in between them does not execute sequentially. This is driving me mad. I can’t understand it. I know this is the way its meant to be and this is completely normal in this new event driven world but I can’t wrap my head around it.
Why can’t I make this work sequentially? Thank you very much for your patience with me.