Android Force关闭ProgressDialog

时间:2011-01-22 16:13:28

标签: android multithreading asynchronous rss

我试图在抓取RSS提要时显示不确定的ProgressDialog。我得到弹出的对话框,但是一旦返回结果,我就会关闭一个力。我怀疑是适配器已填充并继续更新UI。代码如下。我的怀疑是否正确?

        public void getRSS(String rss)
    {

        new GetRSS().execute(rss);

    }
    private class GetRSS extends AsyncTask<String, Void, Void>
    {
        private ProgressDialog Dialog = new ProgressDialog(View2.this);

        protected void onPreExecute() {

            Dialog.setMessage("Please wait...");
            Dialog.show();
        }

        protected void onPostExecute(Void nothing)
        {
            Dialog.dismiss();
        }

        protected Void doInBackground(String... rss) {
        URL feedUrl;
        try
            {
                feedUrl = new URL(rss[0]);

                SyndFeedInput input = new SyndFeedInput();
                SyndFeed feed = input.build(new XmlReader(feedUrl));
                List entries = feed.getEntries();

                Iterator iterator = entries.listIterator();
                while (iterator.hasNext())
                    {
                        SyndEntry ent = (SyndEntry) iterator.next();
                        String title = ent.getTitle();
                        //String uri = ent.getUri();
                        //d.add(uri);

                        SyndContent content = (SyndContent)ent.getContents().get(0);
                        d.add(content.getValue());
                        adapter.add(title);
                    }
                adapter.notifyDataSetChanged();
            }
        catch (MalformedURLException e)
            {
                e.printStackTrace();
            }
        catch (IllegalArgumentException e)
            {
                e.printStackTrace();
            }
        catch (FeedException e)
            {
                e.printStackTrace();
            }
        catch (IOException e)
            {
                e.printStackTrace();
            }
        return null;
        }
    }
    */

这是堆栈转储 - 显然是对通知的调用是问题。现在我只是想弄清楚在哪里打电话通知:

01-22 12:02:28.701: ERROR/WindowManager(571): Activity com.digthisband.dtb.jg.View2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e6ae88 that was originally added here

01-22 12:02:28.701:ERROR / WindowManager(571):android.view.WindowLeaked:Activity com.digthisband.dtb.jg.View2泄露了窗口com.android.internal.policy.impl.PhoneWindow $最初添加的DecorView @ 43e6ae88 01-22 12:02:28.701:ERROR / WindowManager(571):在android.view.ViewRoot。(ViewRoot.java:247) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.view.Window $ LocalWindowManager.addView(Window.java:424) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.app.Dialog.show(Dialog.java:241) 01-22 12:02:28.701:ERROR / WindowManager(571):at com.digthisband.dtb.jg.View2 $ GetRSS.onPreExecute(View2.java:97) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.os.AsyncTask.execute(AsyncTask.java:391) 01-22 12:02:28.701:ERROR / WindowManager(571):at com.digthisband.dtb.jg.View2.getRSS(View2.java:87) 01-22 12:02:28.701:ERROR / WindowManager(571):at com.digthisband.dtb.jg.View2.onCreate(View2.java:68) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.os.Handler.dispatchMessage(Handler.java:99) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.os.Looper.loop(Looper.java:123) 01-22 12:02:28.701:ERROR / WindowManager(571):在android.app.ActivityThread.main(ActivityThread.java:4627) 01-22 12:02:28.701:ERROR / WindowManager(571):at java.lang.reflect.Method.invokeNative(Native Method) 01-22 12:02:28.701:ERROR / WindowManager(571):at java.lang.reflect.Method.invoke(Method.java:521) 01-22 12:02:28.701:ERROR / WindowManager(571):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 01-22 12:02:28.701:ERROR / WindowManager(571):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-22 12:02:28.701:ERROR / WindowManager(571):at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

最好是你可以显示错误LogCat,它会说出导致异常的原因。 我还注意到你在doInBackground方法中调用了notifyDataSetChanged() - 你应该只在UI线程中调用它。