android - How to display ProgressDialog when preparing to show another activity? -
i need show activity mapview, if user long clicked on list item. process takes while, show user progressdialog, while application hangs. here code:
listview listview = (listview) findviewbyid(android.r.id.list); listview.setonitemlongclicklistener (new onitemlongclicklistener() { public boolean onitemlongclick(adapterview parent, view view, int position, long id) { ... progressdialog dialog = progressdialog.show(getapplicationcontext(), "", "loading. please wait...", true); intent intent = new intent(getbasecontext(), map.class); startactivity(intent);
have chosen correct approach? getting different fcs (depending on context chosen progressdialog). can progressbar shown in scenario?
upd. i've tried show toast before starting activity. again, toast shown when map displayed. don't understand happens. if remove startactivity code, toast displayed immediately.
are doing lenghty preparation in mapview's oncreate() ? should not because block ui thread....
instead should - inside of map activity's oncreate(), should spawn new asynctask (ideally) , show progress bar there (and exit oncreate() right after showing progress bar). in asynctask after finishes (in postexecuted()) should dismiss progress dialog , show map. postexecuted() run in ui thread can safely dismiss progress bar.
fcs have , possibly anrs (not responding) coming because things in/out of ui thread. should create/dismiss ui components in ui thread, , shoudl not run lenghty operation in ui thread. that's rule of thumb.
Comments
Post a Comment