Hi,
My app is required to load some data (from the settings) and do calculations on that data. Currently my app will automatically load the data in the "onStart" function, which means that for larger datasets, it takes upwards of 30-40 seconds to load and do all the calculations, and more significantly, the user is not presented with any splash screen or progress bar indicating it is in fact working, leading users to believe it may not be working or doing anything at all. So, I can move the loading procedures into a subprocedure, which will run when the user selects a menu option 'Load Data'. The problem remains, however, that if the loading process takes more than 5-10 seconds, there is little other feedback provided to the user during this time. The app can display a small text string "loading" but I would like it to display a 'busy' ProgressBar.
-------
My Goal is -- When the user selects 'Load Data' option, my app initiates the below processes--
- The screen displays a ProgressBar BehaviorDelegate ('busy' option)
- (beginning and continuing as the ProgressBar is 'busy') The app conducts loading procedures/calculations**
- If user presses 'back', it will terminate the loading procedures/calculations and pop the ProgressBar BehaviorDelegate
-------
**I'm not exactly sure how to code the loading procedures/calculations. With enough data in the settings, the total mass of calculations could trip the watchdog (ie too many calculations), so I have divided it into different work segments. I am thinking of using a state variable and having a function which conducts the calculations not all at once, lowering risk of tripping watchdog.
// global variable, or could even implement as parameter for below function var state = 0; loadData() { if (state == 0) { // do 1st segment of procedures/calculations state += 1; } else if (state == 1) { // do 2nd segment of procedures/calculations state += 1; } else if (state == 2) { /// ... and so on // finished with procedures/calculations } }
The separate segments of the procedures/calculations take different times to complete, and some of them I cannot break down into smaller components, therefore I would prefer the ProgressBar continue to display 'busy' even while the calculations are taking place. Or maybe it makes more sense to display a "percentage complete" ProgressBar, rather than a "busy" so then, the user can at least see which segment is ongoing.
But I am still unsure how to code the ProgressBar piece. Would it work to call this loadData function from inside the initialize() function of the progressBar? Since some of the segments last several seconds, it doesn't make sense to me, to call this loadData function every second, as in tie it to a timer. (But maybe it would work - to tie the execution of this function to a timer so it checks it every second, if it's not complete with previous calculations?)
-------
#TLDR...
I know I can send it "busy" command, and change the text displayed, but I'm concerned that if my calculations take too long, it will not update the animation of the 'busy' progress bar. So I'm more curious on HOW TO ORGANIZE THE CODE inside or outside the ProgressBar BehaviorDelegate, so it can complete the calculations, update the ProgressBar 'busy' animation, and also accept Back input and not appear unresponsive while all this is going on.
Thanks in advance for any help!