I am parsing the xml file containing some names using the Async task and populating these names to the listview again via the main thread. But whats happening in my case is, when the Async task is still running, the main thread is already populating the names to the listview which is resulting in no items on the listview. Should i make the main thread wait until the Async task finish the job or is there any other way to solve this prob.? if yes how can i make the main thread wait when i don't know that how long the Async task might take to finish.?
If you want to complete the AsycTask then you can use .get()
method from AsyncTask. (Which will block the MainUiThread)
But I think the best approach is without blocking MainUiThread you have to start ProgressDialog on onPreExecute()
and after populating ListView in onPostExecute()
of AsyncTask finish the ProgressDialog in onPostExecute()
.
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