I have a lengthy stretch of code which can run from 1 second to 7 seconds, depending on the difficulty
of the problem it's solving. Once the solution goes beyond a couple seconds, it looks like the app is
doing nothing, so I wanted to put a "Working..." progressdialog up to show the user that everything was under control. I set a timer and when it ticks, the progressdialog is supposed to pop open. Only it doesn't. (Actually, it does open after the problem has been solved.)
I tried adding some strategically placed doevents, and while that helps a little, the progressdialog barely pops open before the solution has been reached. And the more doevents I add, the longer the app takes. Finding the best spot(s) is tough.
So I thought I would try to put the long running part in a service and put the timer and the progressdialog in the main activity. Just before I start the service, I enable the timer. I would have thought that the service would run in the background (that is, giving up some of its time slots) and the main activity would get the focus periodically and see the timer had ticked and be able to open the progressdialog. But no luck. I also tried a toast message.
And, just out of curiosity, I tried to open the progressdialog (without a timer) before starting the service. Oddly, that works best of all, even though the dialog doesn't actually appear on the screen until several seconds later. And no timer is involved. Assuming I could guarantee that the delay would always be consistent, I could live with it. But that's quite a quirky workaround to depend on.
So, is doevents (in the right spot) the way to handle this? Doesn't "run in the background" imply yielding? Services are always presented as allowing the main activity to continue while the background processing takes place. That's what I'm trying to do.
Last, I'm reluctant to use the notification feature (assuming it worked in this case). I would like a big spinning "Working..." progressdialg in the middle of the screen. A notification looks like you're getting a text message or some notice from Playstore.
Any guidance is appreciated.
-go
of the problem it's solving. Once the solution goes beyond a couple seconds, it looks like the app is
doing nothing, so I wanted to put a "Working..." progressdialog up to show the user that everything was under control. I set a timer and when it ticks, the progressdialog is supposed to pop open. Only it doesn't. (Actually, it does open after the problem has been solved.)
I tried adding some strategically placed doevents, and while that helps a little, the progressdialog barely pops open before the solution has been reached. And the more doevents I add, the longer the app takes. Finding the best spot(s) is tough.
So I thought I would try to put the long running part in a service and put the timer and the progressdialog in the main activity. Just before I start the service, I enable the timer. I would have thought that the service would run in the background (that is, giving up some of its time slots) and the main activity would get the focus periodically and see the timer had ticked and be able to open the progressdialog. But no luck. I also tried a toast message.
And, just out of curiosity, I tried to open the progressdialog (without a timer) before starting the service. Oddly, that works best of all, even though the dialog doesn't actually appear on the screen until several seconds later. And no timer is involved. Assuming I could guarantee that the delay would always be consistent, I could live with it. But that's quite a quirky workaround to depend on.
So, is doevents (in the right spot) the way to handle this? Doesn't "run in the background" imply yielding? Services are always presented as allowing the main activity to continue while the background processing takes place. That's what I'm trying to do.
Last, I'm reluctant to use the notification feature (assuming it worked in this case). I would like a big spinning "Working..." progressdialg in the middle of the screen. A notification looks like you're getting a text message or some notice from Playstore.
Any guidance is appreciated.
-go