android :: show progress dialog till asynctask does not get complete -


i downloading zip file of 15 mb , unzip in sd card. using progress dialog show status. first time works perfectly, , when change db version number on server download new file , start app again progress dialog disappears in between , causes crash in app.

below code.

class checkinappupdatesasynctask extends asynctask<void, void, void> {      dialog  progress;       @override     protected void doinbackground(void... params) {          try {             downloaddb();          } catch (exception e) {         }       } @override     protected void onpostexecute(final void result) {          stopworking();     }      @override     protected void onpreexecute() {          startworking();     }   };5   private void startworking() {      synchronized (this.diagsynch) {         if (this.pdiag != null) {             this.pdiag.dismiss();         }          this.pdiag = progressdialog.show(browse.context, "working...",                 "please wait while load encyclopedia.", true, false);     } }      private void stopworking() {      synchronized (this.diagsynch) {         if (this.pdiag != null) {             this.pdiag.dismiss();         }     } } 

download code

url url = new url(serverfileurl);         log.d("file_urllink", "serverfileurl " + serverfileurl);         urlconnection connection = url.openconnection();         inputstream input = connection.getinputstream();         connection.getcontentlength();          byte data[] = new byte[1024];         input = new gzipinputstream(input);         inputsource = new inputsource(input);         inputstream in = new bufferedinputstream(is.getbytestream());         string inappdbname = constants.new_db_name_to_download;          outputstream output = new bufferedoutputstream(new fileoutputstream(dir + "/" + inappdbname));          int length;         while ((length = in.read(data)) > 0) {             output.write(data, 0, length);         }          output.flush();         output.close();         input.close(); 

any idea?

you should put unzip code before stopworking(); in onpostexecute.

it not close till things happen.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -