【发布时间】:2018-07-30 08:39:44
【问题描述】:
我找不到使用 AsyncTask 更新 UI 的方法
这是我的伪代码
public class MissionsActivity extends Activity {
private class UpdateMissions extends AsyncTask<Void, Long, Void> {
protected Void doInBackground(Void... voids) {
while(true) {
try {
Thread.sleep(250);/
/*HERE I GET time1, time2, time3 and currentTime READING A FILE*/
publishProgress(time1,time2,time3,currentTime);
} catch (Exception e) {
}
}
}
protected void onProgressUpdate(Long time1, Long time2, Long time3, Long currentTime) {
/*HERE I MANIPOLATE time1, time2, time3 and currentTime TO UPDATE THE UI*/
}
然后在主类(继承Activity的那个)中,在onCreate中我做
update = new UpdateMissions();
update.execute(null,null,null);
但它什么也没做。我真的在这里碰壁了,我需要认真的帮助,因为我以前从未使用过 AsyncTask。
while(true) 部分不允许我进入 pre 或 post 执行方法,所以我必须使用进度之一,但我无法找到错误所在。
提前致谢
【问题讨论】: