Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个正在运行的 asynctask 线程,其中显示了一个进度对话框。在它运行时,我还有另一个更新 UI 的可运行线程。但是,似乎更新 UI 似乎会锁定进度对话框,直到它完成更新。进度对话框是否位于主 UI 的单独异步任务部分?
您应该使用 的方法onProgressUpdate来AsyncTask显示进度(即更新 UI)。覆盖这样的方法 -
onProgressUpdate
AsyncTask
protected void onProgressUpdate(Integer... progress) { YOUR_ACTIVITY_INSTANCE.setProgressPercent(progress[0]); }
您可以调用publishProgressfrom 方法doInBackground来触发onProgressUpdate和更新 UI(如需要时显示百分比)。
publishProgress
doInBackground