Android 4.0以降、問題があります(2.3.6では動作しています)。
onProgressUpdate
既に UI スレッドにあるはずです。私がactivity.runOnUiThread
今試したのはHandler
バージョンで、ofcは最初は何もありませんでした。修正方法は?
public class ReadDataTask extends AsyncTask<String, String, JSONArray> {
private Activity activity;
protected ProgressDialog dlg;
private long startRead, endRead, endJson;
public ReadDataTask(Activity activity) {
this.activity = activity;
dlg = new ProgressDialog(activity);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
dlg.show();
startRead = System.currentTimeMillis();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
if (values != null && values.length > 0) {
final String msg = values[0];
new Handler().post(new Runnable() {
public void run() {
dlg.setMessage(msg);// android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
}
});
}
}
@Override
protected JSONArray doInBackground(String... params) {
... long task here
publishProgress("Converting to JSON: " + (1 + i) + " / " + dataList.size());