When my activity is being closed, I serialize the application state data to file to give me a chance to reload the state if the app gets killed by the system.
This approach (saving and restoring state) works fine. But, sometimes, when the process was killed, and depending on the amount of data to load, the loading state process can least some seconds to complete.
So, I can’t load the state on a separeted thread because my activity will crash if the data isn’t there on the onLoad.
So, I’d like to display a progress dialogue while loading the content, but, ensure that the Activity’s onLoad method will be called only after the loading state process.
Does anybody knows how could I achieve this? Thanks a lot.
Hmmm.. could you Override the
onLoad()function, then add a boolean that states whether you’re displaying the dialog or not. If the dialog is being displayed (the boolean is true), don’t letonLoad()do anything; otherwise, carry on as usual. That way once the dialog is dismissed, you can set the boolean to false again, and ifonLoad()isn’t called by default afterwards, perhaps you could manually call it? This is just an idea.In other words: the dialog can be displayed using an AsyncTask. In the
onPreExecute()method, set the boolean to true, do everything you need indoInBackground(), and inonPostExecute(), set the boolean to false and callonLoad().On a side note… do you mean
onCreate()oronResume()? I’ve actually not heard ofonLoad(), unless this is a function you created.