Reputation: 6941
I've got an TabActivity implementing TabContentFactory, which starts an AsyncTask in onCreate() to fetch the data for the tabs. When the AsyncTask has finished, onPostExecute() could directly update the UI-elements, right? Meaning, since that method runs in the UI-Thread no further thread-synchronization would be required when accessing UI-elements?
Anyway, the problem I have is that my UI-Thread calls createTabContent() in the TabActivity while the AsyncTask is still busy. I have to add at least one tab, or I get a NullPointerException. But how do I only add tabs when my AsyncTask has finished and the ProgressDialog has been dismissed?
I'd be glad if someone could help...
Upvotes: 1
Views: 1222
Reputation: 80340
When the AsyncTask has finished, onPostExecute() could directly update the
UI-elements, right? Meaning, since that method runs in the UI-Thread no further
thread-synchronization would be required when accessing UI-elements?
Right.
Anyway, the problem I have is that my UI-Thread calls createTabContent() in the
TabActivity while the AsyncTask is still busy.
If you need to update UI while AsyncTask is still running in background, then override AsyncTask.onProgressUpdate(..) and then call AsyncTask.publishProgress(..) from within the AsyncTask.doInBackground(..).
I have to add at least one tab, or I get a NullPointerException. But how do I
only add tabs when my AsyncTask has finished and the ProgressDialog has been
dismissed?
I don't understand this. Could you please explain in more detail?
Anyway, watch for this things:
Upvotes: 1