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.
AsyncTask がまだバックグラウンドで実行されている間に UI を更新する必要がある場合は、AsyncTask.onProgressUpdate(..) をオーバーライドしてから、AsyncTask.doInBackground(..) 内から AsyncTask.publishProgress(..) を呼び出します。
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?
私はこれを理解していません。詳しく説明していただけますか?
とにかく、次のことに注意してください。
- TabActivity が完全に作成された後にのみ、AsyncTask を開始します。onCreate() ではなく onPostCreate() から開始します。これが NullPointerException の原因である可能性があります。
- AsyncTask.onPostExecute(..) 内の UI スレッドから任意のアクティビティを更新できます。
- AsyncTask がまだバックグラウンドで実行されている間に UI を更新する必要がある場合は、AsyncTask.doInBackground(..) 内から AsyncTask.publishProgress(..) を呼び出します。