I have a background service that does some heavy lifting within a transaction once a day. If the user happens to start the app at this time, I want them to sit tight till it finishes (around 10 secs or so). What's the best way to do this across all activities? Check if the service is running in the "onResume" function of each activity? And how do we know when it's done? Local broadcasts I'm guessing...
Best practices anyone?
UPDATE: I've managed to stall "onResume" till my service is done. The problem is that the user just sees a blank screen till then. I've tried progressdialogs and regular dialogs while onResume is paused. But they all display only when onResume returns and that defeats the purpose. In other words, Progress dialog doesn't "show" immediately after "show()" is called :(
I would have a 'I'm busy processing' flag in the db.
And the app should check on start up, and then lock the app in a nice way, and then check say every x seconds to see the state of the flag. It could do this during normal processing so every action checks this flag locally and on the server before starting.
Seems like a simple way of locking. So you will have to take contention into account (multiple users setting and unsetting) possibly using a a semaphore type arangement.
Local broadcasts is good.
Have your activities question the service if it is busy or not, and display an appropriate message to the user before finishing the activity.
Once the service is done, have it send an intent that it is finished.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With