I have function onClickButton where i do (pseudocode):
show activityIndicatorView (or ProgressBar or change label text no matter)
execute my algorithm
hide activityIndicatorView
actvitiyIndicatorView will never show. If I delete hide at the end of the function, then it will emerge after algorithm. In spite of I show it before execute algorithm.
Why and how I can fix it ?
Most probably your execute my algorithm is a long cpu time consuming process which is called on the main thread…
you are also showing the activity indicator just before the algorithm…The UI normally takes some time to update the layout (adding your activity indicator..) ..but before it does..your a;gorith takes place on the main thread..and it block the UI update.. so when the task completes.. you tell to hide activity..and your activity hides….that is why you can’t see it being added and then removed from view..
To solve this..do the algorithm task in a separate thread(no the main thread) ..this way UI will be updated and task will complete in the background..
Alternative way is to perform the long task after some delay..so that UI update itself