asyncTask 和 ProgressDialog :冻结

发布于 2024-11-30 08:12:30 字数 3370 浏览 4 评论 0原文

请查看我的代码..如果可以的话,请告诉我为什么当函数在后台完成一半时我的progressDialog停止,屏幕挂起(没有显示任何内容,logcat显示我在后台函数中放入的所有日志)。

然后,就在结束之前,progressDialog再次开始动画并在几秒钟后关闭(功能完成并且结果正常显示)

public class changeWall extends AsyncTask<Integer, Integer, Integer> {
        protected Integer doInBackground(Integer... urls) {
            int totalSize=0;
            try {

                 if(s.loadBoolean() == false)
                {
                     log("IF = false");
                     log("tempLogin = "+tempLogin);
                     log("tempPassword = "+tempPassword);
                     getNewResponse(tempLogin,tempPassword);
                if(needSave)
                {
                 s.saveBoolean(true);
                }

                }
                 else
                 { 
                if(s.loadLogin()==null)
                { 
                   getNewResponse(tempLogin,tempPassword);
                }else
                {
                    getNewResponse(s.loadLogin(),s.loadPassowrd());
                }
                 } 
                parser.setLol(0);

                parser.startParse(RESULT_STRING);

             log("end parse");
            } catch (ClientProtocolException e) {
                log("internet connection lost");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log(" connection lost");
            }
            log("count = "+parser.getFacebookId(1));
            publishProgress();
            totalSize=1;
            log("end of start");
            return totalSize;
        }

        protected void onProgressUpdate(Integer... progress) {
            log("wall click ON PROGRESS UPDATE");
            wall.setBackgroundResource(R.drawable.tabbuttonon);
            messages.setBackgroundResource(0);
            activity.setBackgroundResource(0);
            profile.setBackgroundResource(0);
            l1_1.setBackgroundResource(R.drawable.tabbuttononleft);
            l1_2.setBackgroundResource(R.drawable.tabbuttononright);
            l2_1.setBackgroundResource(0);
            l2_2.setBackgroundResource(0);
            l3_1.setBackgroundResource(0);
            l3_2.setBackgroundResource(0);
            l4_2.setBackgroundResource(0);
            l4_2.setBackgroundResource(0);
            wall.setTextColor(Color.BLACK);
            messages.setTextColor(Color.WHITE);
            profile.setTextColor(Color.WHITE);
            activity.setTextColor(Color.WHITE);

            try {
                loadWall();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

            }
               wallProgres.dismiss();
        }

        protected void onPostExecute(Long result) {
           if(result==1)
           {
               log("end WallChange");

           }
        }
    }

简单的地图如下所示:

----start progress(progress.show())
----start function
--- animation (progressDialog)
---animation(---)
---animation(---)
---FREEZ
---FREEZ(Function steel working normal, progressDialog in freeze mode)
---animation
---end function
---progress.dismis();//

我在这里发现了类似的问题..(这个问题=我的问题但是无需下载)使用 AsyncTask 冻结 UI 线程 问候,彼得。

please see my code .. and if you can, tell me why my progressDialog stopped when the function is halfway done in the background, the screen hangs (nothing is displayed, the logcat shows all logs i put in the background function).

Then, right before the end, the progressDialog starts animating again and closes after a couple seconds (the function is finished and the result is displayed normally)

public class changeWall extends AsyncTask<Integer, Integer, Integer> {
        protected Integer doInBackground(Integer... urls) {
            int totalSize=0;
            try {

                 if(s.loadBoolean() == false)
                {
                     log("IF = false");
                     log("tempLogin = "+tempLogin);
                     log("tempPassword = "+tempPassword);
                     getNewResponse(tempLogin,tempPassword);
                if(needSave)
                {
                 s.saveBoolean(true);
                }

                }
                 else
                 { 
                if(s.loadLogin()==null)
                { 
                   getNewResponse(tempLogin,tempPassword);
                }else
                {
                    getNewResponse(s.loadLogin(),s.loadPassowrd());
                }
                 } 
                parser.setLol(0);

                parser.startParse(RESULT_STRING);

             log("end parse");
            } catch (ClientProtocolException e) {
                log("internet connection lost");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log(" connection lost");
            }
            log("count = "+parser.getFacebookId(1));
            publishProgress();
            totalSize=1;
            log("end of start");
            return totalSize;
        }

        protected void onProgressUpdate(Integer... progress) {
            log("wall click ON PROGRESS UPDATE");
            wall.setBackgroundResource(R.drawable.tabbuttonon);
            messages.setBackgroundResource(0);
            activity.setBackgroundResource(0);
            profile.setBackgroundResource(0);
            l1_1.setBackgroundResource(R.drawable.tabbuttononleft);
            l1_2.setBackgroundResource(R.drawable.tabbuttononright);
            l2_1.setBackgroundResource(0);
            l2_2.setBackgroundResource(0);
            l3_1.setBackgroundResource(0);
            l3_2.setBackgroundResource(0);
            l4_2.setBackgroundResource(0);
            l4_2.setBackgroundResource(0);
            wall.setTextColor(Color.BLACK);
            messages.setTextColor(Color.WHITE);
            profile.setTextColor(Color.WHITE);
            activity.setTextColor(Color.WHITE);

            try {
                loadWall();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

            }
               wallProgres.dismiss();
        }

        protected void onPostExecute(Long result) {
           if(result==1)
           {
               log("end WallChange");

           }
        }
    }

simple map as this showed :

----start progress(progress.show())
----start function
--- animation (progressDialog)
---animation(---)
---animation(---)
---FREEZ
---FREEZ(Function steel working normal, progressDialog in freeze mode)
---animation
---end function
---progress.dismis();//

similar problem i found here..(this problem = my problem but without download) Freezing UI Thread with AsyncTask
Regards,Peter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羁绊已千年 2024-12-07 08:12:30

它可能不正确,但放置

wallProgres.dismiss();
 in  onPostExecute rather than in onProgessUpdate method.

是因为 onProgressUpdate 在运行时调用,但 onPostExecute 在执行后调用。

希望有帮助..

It may not be correct but place

wallProgres.dismiss();
 in  onPostExecute rather than in onProgessUpdate method.

beacuse onProgressUpdate calls while running , but onPostExecute calls after execution.

Hope it helps..

平生欢 2024-12-07 08:12:30

将此行 "wallProgres.dismiss()" 放入 onPostExecute() 中。

   protected void onPostExecute(Long result) {
               if(result==1)
               {
                   log("end WallChange");

               }
               if(wallProgress.isShowing())
                       wallProgres.dismiss();
      }

place this line "wallProgres.dismiss()" in onPostExecute().

   protected void onPostExecute(Long result) {
               if(result==1)
               {
                   log("end WallChange");

               }
               if(wallProgress.isShowing())
                       wallProgres.dismiss();
      }
梦过后 2024-12-07 08:12:30

将此行放入

wallProgres.dismiss();

onPostExecute() 方法中

protected void onPostExecute(Long result) {
           if(result==1)
           {
               log("end WallChange");
               wallProgres.dismiss();
           }
        }

put this line

wallProgres.dismiss();

in onPostExecute() method

protected void onPostExecute(Long result) {
           if(result==1)
           {
               log("end WallChange");
               wallProgres.dismiss();
           }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文