android - UI delayed showing with asynctask -


i defined asynctask in button's onclicklistener, , once user clicks button, ideally progress dialog shows while asynctask downloading.

however, progress dialog flashes in , disappears before results returned, , button gets focused while asynctask works in background.

can me figure out did wrong here? code snippet:

    final progressdialog progressdialog = new progressdialog(context);     progressdialog.setprogressstyle(progressdialog.style_spinner);      ((button)findviewbyid(r.id.buttonloginactivity)).setonclicklistener(new onclicklistener() {         @override         public void onclick(view v) {             asynctask<void, void, void> downloadtask= new asynctask<void, void, void>(){                 @override                 protected void doinbackground(void... params) {                     string data = service.getsomedata();                             context.getcontentresolver.notifychange("content://some_url");                         return null;                 }                  @override                 protected void onpostexecute(void result) {                     super.onpostexecute(result);                     if(progressdialog== null) return;                     if(progressdialog!=null) {                         progressdialog.dismiss();                         progressdialog = null;                     }                 }             };              progressdialog.show();              downloadtask.execute();             try{                 downloadtask.get();             }catch(exception e){                 e.printstacktrace();                 return;             }         }     }); 

don't use get()

downloadtask.get(); 

this blocking call. docs

waits if necessary computation complete, , retrieves result.

just use execute() need results in onpostexecute()


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -