ProgressDialog not shown in UIThread

泄露秘密 提交于 2019-12-31 05:16:06

问题


I'm creating a map using the google api lib. Because the mapwidget takes a long time to load I'm trying to add a loading notification, but it isn't shown. I can show the progressDialog in regular threads though. How come this dialog isn't shown?

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        progressDialog = ProgressDialog.show(this, "Please Wait", "Map = loading",false,true);
        //setContentView(R.layout.map);
        runOnUiThread(new Runnable(){
            public void run() {
                try{
                    Log.d("debug", "before setContentView");                        //13:36:25
                    setContentView(R.layout.map);
                    Log.d("debug", "after setContentView");                         //13:36:39

                } catch (Exception e) { }

                progressDialog.dismiss();
            }});

        initMap();     
        initGps();

    }

回答1:


It is pointless to put up a ProgressDialog for a MapActivity because "the mapwidget takes a long time to load", because you have no way to know when the MapView is done loading, so you have no way to know when to dismiss the dialog. setContentView() itself should run fairly quickly; the actual loading of the map tiles happens asynchronously.

Note that the time it takes to display a MapView is mostly dependent upon the Internet connection back to the Google Maps servers. In most cases, it does not take particularly long, certainly not long enough to warrant a ProgressDialog.




回答2:


Used this as a solution:

http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/



来源:https://stackoverflow.com/questions/5485832/progressdialog-not-shown-in-uithread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!