Progressdialog Appears Too Late And Dissapears Too Fast
Solution 1:
Ok I think that this
runOnUiThread(new Runnable() {
is causing this behavior.
doInBackground() executes your code in a new thread to the main UI thread. You are then putting the code to execute in this thread back into the main one causing the progress dialog to be delayed at the end and then in postExecute() it gets closed immediately.
A good asyntask tutorial can be found here.
Solution 2:
You must not use runOnUiThread
. What you're basically did is:
- Started new non-ui thread
- From this new non-ui thread you posted a long running task to UI thread.
- Exited from non-ui thread.
- Your ui thread now executes long-running operation (
RefreshDataBase
) and blocks the UI.
You should call RefreshDataBase()
directly. And if this method touches UI, you have to refactor it.
Solution 3:
I have solved it, using this answer of Vladimir Ivanov.
I have separated the functionality by the appearance.
I have kept the functionality(downloading new data) in doInBackground()
and in onPostExecute()
I updated the list: get the new adapter,called setListAdaper()
and notifyDataSetChanged
.
Of course, I quit using runOnUiThread()
. Thanks to all for hints.
Post a Comment for "Progressdialog Appears Too Late And Dissapears Too Fast"