开发者

ProgressDialog not shown in UIThread

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");                      开发者_StackOverflow  //13:36:25
                    setContentView(R.layout.map);
                    Log.d("debug", "after setContentView");                         //13:36:39

                } catch (Exception e) { }

                progressDialog.dismiss();
            }});

        initMap();     
        initGps();

    }


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.


Used this as a solution:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜