Android 继续ProgressDialog,直到onPostExecute完成

Android 继续ProgressDialog,直到onPostExecute完成,android,android-asynctask,jsoup,Android,Android Asynctask,Jsoup,我知道如果进程对话框没有在onPostExecute()中立即终止,它将停止旋转。但是,我在onPostExecute()内部调用了一些方法,我无法将它们转移到doInBackground(),因为这些方法应该在UI上运行。在调用这些方法后,是否有可能在不停止旋转的情况下继续progressDialog 以下是我的AsyncTask的onPostExecute: protected String doInBackground(final String... strings) { //Networ

我知道如果进程对话框没有在
onPostExecute()
中立即终止,它将停止旋转。但是,我在
onPostExecute()
内部调用了一些方法,我无法将它们转移到
doInBackground()
,因为这些方法应该在UI上运行。在调用这些方法后,是否有可能在不停止旋转的情况下继续
progressDialog

以下是我的
AsyncTask
onPostExecute

protected String doInBackground(final String... strings) {
//Network activity here
    }

protected void onPostExecute(String unused){  
//progressdialog stops spinning here, cannot change the message also
try {
            if(response.equals("HOST ERROR") || response.equals("CONNECTION ERROR") ||  response.equals("ERROR")){
                new AlertDialog.Builder(context).setTitle("Error").setMessage("Cannot connect to the internet.").setNeutralButton("Close", null).setIcon(android.R.drawable.ic_delete).show();
        }
            else{
                doc = Jsoup.parse(response);
                Intent cc = new Intent(activity,com.sblive.aufschoolbliz.GradeBook.class);
                subjectCodes = getSubjectCodes(); //this parsing method should run on UI
                professors = getProfs(); //this parsing  method should run on UI
                grades = getGrades(); //this parsing  method should run on UI
                cc.putExtra("subjectCodes", subjectCodes);
                cc.putExtra("professors", professors);
                cc.putExtra("grades", grades);

                if(this.pd.isShowing()) {
                    this.pd.dismiss();
                }
                context.startActivity(cc);
            }
        }

        catch (NullPointerException e) {

        }
    }
>

好吧,忘了我贴的东西吧,傻我。当然,任何修改用户界面的操作都需要在UI线程上调用/取消

因此,我要做的是在doInBackground()期间运行所有可能的操作,并创建/删除对话框或任何需要在UI线程上显式运行的操作,如下所示:

this.runOnUiThread(new Runnable() {
  public void run() {
    /*Code required to run on UI thread*/  }
});

如果我要将这些解析方法转移到doInBackground()并使用activity.runOnUIThread,我将如何等待我的网络活动首先完成并执行这些方法?如果这些方法花费很长时间,您可以看到进度条被阻塞,然后,应该考虑使用另一个异步任务(用另一个进度条)实现它们。将需要在UI线程上执行的部分迁移到新的AsyncTask的onPostExecute()中我试图将其放入doInBackground中,但遇到一个异常:无法在未调用Looper的线程内创建处理程序。准备()是的,您无法在AsyncTask线程内调用它。尝试在UI线程上调用它。在UI线程上启动和关闭它。尝试使用AsyncTask的onPreExecute()回调,我相信它是在UI线程上调用的。希望有帮助!我搞不懂。。我现在试图将它放在onPreExecute()中,但给出了相同的错误,我会将所有代码放在doInBackground()中,以及该代码段中需要UI线程的部分。你可以任意多次调用runOnUiThread。是的,很遗憾,无法在其UI线程之外创建/关闭视图。如果您想让旋转变得完美,那么您可以做的是创建一个具有该进度对话框布局的自定义活动,然后在onPause()回调中使用overridePendingTransition(0,0),以防止在finish()后缩小动画,并使用intent.addFlags(intent.FLAG\u activity\u NO\u animation);为了通话目的。一旦activty设置完毕,在onPreExecute()和onPostExecute()中调用并取消它。现在应该允许您这样做,因为创建活动不依赖于任何上下文。