【发布时间】:2016-10-26 05:11:01
【问题描述】:
我在onCreate 中有这个GetAllUsers();,我有这个
private void GetAllUsers() {
(new LoadingUsers(this)).execute();
}
那我有这个
private class LoadingUsers extends AsyncTask < Void, Integer, String > {
String TAG = getClass().getSimpleName();
AlertDialog.Builder builderSingle;
ArrayAdapter < String > arrayAdapter;@
SuppressWarnings("unused")
Context mContext;
public LoadingUsers(Context context) {
super();
mContext = context;
}
protected void onPreExecute() {
// prgDialog.show();
// builderSingle = new
Log.d(TAG + " PreExceute", "On pre Exceute......");
}
protected String doInBackground(Void...arg0) {
Log.d(TAG + " DoINBackGround", "On doInBackground...");
return null;
}
protected void onProgressUpdate(Integer...a) {
super.onProgressUpdate(a);
Log.d(TAG + " onProgressUpdate", "You are in progress update ... " + a[0]);
}
protected void onPostExecute(String result) {
// prgDialog.hide();
Log.d(TAG + " onPostExecute", "" + result);
MainActivity.this.pd.dismiss();
}
}
我想在protected void onProgressUpdate(Integer... a) { 中添加一个builderSingle = new AlertDialog.Builder(MainActivity.this);,它有一个AsyncHttpClient client = new AsyncHttpClient();,但不幸的是onProgressUpdate 根本没有被调用。我知道这一点,因为日志没有显示。除了onProgressUpdate 我也有
@
Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "On Destroy .....");
}
@
Override
protected void onPause() {
super.onPause();
Log.i(TAG, "On Pause .....");
}
@
Override
protected void onRestart() {
super.onRestart();
Log.i(TAG, "On Restart .....");
}
@
Override
protected void onResume() {
super.onResume();
Log.i(TAG, "On Resume .....");
}
@
Override
protected void onStart() {
super.onStart();
Log.i(TAG, "On Start .....");
}
@
Override
protected void onStop() {
super.onStop();
Log.i(TAG, "On Stop .....");
}
OnStart 和 OnResume 也在记录中。
为什么没有调用 onProgressUpdate? 如何正确调用 onProgressUpdated?
Update
onPostExecute 也被调用,onProgressUpdate 不是
【问题讨论】:
-
我认为您需要在 doInBackGround() 中调用 publishProgress?
-
你在哪里调用 publishProgress?
-
@Raghavendra 是问题还是答案?因为从我在 SO 中找到的示例中,他们不会在 doInBackGround 上调用它
-
@BrownmanRevival 不,您需要调用 publishProgress 来获取 onProgressUpdate 的更新。
-
@BrownmanRevival 使用 publishProgress(Progress...) 发布一个或多个进度单位。这些值发布在 UI 线程的 onProgressUpdate(Progress...) 中。它是一个答案:)
标签: java android async-onprogressupdate