我android.os.AsyncTask
对处理方法很陌生android.app.ProgressDialog
。我遇到了通过处理特定查询android.database.Cursor
并将其转换为我需要的实体的问题。
我正在关注这个模板,但它总是返回给我一个android.view.WindowManager$BadTokenException
.
List<Entity> loadData() throws Exception {
AsyncTask<Cursor, Void, List<Entity>> process = new AsyncTask<Cursor, Void, List<Entity>>() {
ProgressDialog dialog;
protected void onPreExecute() {
dialog = ProgressDialog.show(getApplicationContext(), "Please wait...", "Loading data...");
}
protected void onPostExcecute() {
dialog.dismiss();
}
@Override
protected List<Entity> doInBackground(Cursor... params) {
List<Entity> entities = new ArrayList<Entity>();
// process of convertion of data from android.database.Cursor to <pacakge>.Entity
return entities;
}
}.execute(/* the query : android.database.Cursor */)
return process.get();
}
我错过了什么吗?