android - postexecute in asynctask is not executing -
@override protected string doinbackground(string... params) { // todo auto-generated method stub url3="http://www.digitalmarketingbox.com/webtool/boxdata/"+mainactivity.abc+"/updates.zip"; try { httpurlconnection.setfollowredirects(false); // note : may need // httpurlconnection.setinstancefollowredirects(false) httpurlconnection con =(httpurlconnection) new url(params[0]).openconnection(); con.setrequestmethod("head"); x=con.getresponsecode() == httpurlconnection.http_ok; } catch (exception e) { e.printstacktrace(); x=false; } try { httpurlconnection.setfollowredirects(false); // note : may need // httpurlconnection.setinstancefollowredirects(false) httpurlconnection con =(httpurlconnection) new url(url3).openconnection(); con.setrequestmethod("head"); xc=con.getresponsecode() == httpurlconnection.http_ok; } catch (exception e) { e.printstacktrace(); xc=false; } //x=exists(params[0]); //xc=exists(url3); valve=string.valueof(x); if(valve.equals("true")) { finalurl=url+ mainactivity.abc + "/resources.zip"; filename="resources.zip"; mainactivity.fl1=filename; log.i("filename",filename); } else if(xc==true) { finalurl=url+ mainactivity.abc + "/updates.zip"; filename="updates.zip"; mainactivity.fl1=filename; log.i("filename",filename); } else { try { httpclient client = new defaulthttpclient(); log.i("url checking update",url1); httppost post = new httppost(url1); list<namevaluepair> parameters = new arraylist<namevaluepair>(); parameters.add(new basicnamevaluepair("reqtype", "resendcontent")); parameters.add(new basicnamevaluepair("menuboxid",mainactivity.abc)); parameters.add(new basicnamevaluepair("updatetoken", "dmb20101512")); urlencodedformentity ent; ent = new urlencodedformentity(parameters,http.utf_8); post.setentity(ent); httpresponse responsepost = client.execute(post); httpentity resentity = responsepost.getentity(); finalurl=url+ mainactivity.abc + "/updates.zip"; filename="updates.zip"; mainactivity.fl1=filename; log.i("filename",filename); log.i("url",finalurl); } catch (final ioexception e) { e.printstacktrace(); } try { thread.sleep(2000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } finalurl=url+ mainactivity.abc + "/updates.zip"; filename="updates.zip"; mainactivity.fl1=filename; } try{ url url = new url(finalurl); httpurlconnection urlconnection = (httpurlconnection) url.openconnection(); urlconnection.setrequestmethod("get"); urlconnection.setdooutput(true); urlconnection.connect(); //file sdcardroot = environment.getexternalstoragedirectory(); filedestination=environment.getexternalstoragedirectory() +"/" + filename; //file file = new file(sdcardroot,filename); file file = new file(filedestination); fileoutputstream fileoutput = new fileoutputstream(file); inputstream inputstream = urlconnection.getinputstream(); totalsize = urlconnection.getcontentlength(); log.i("size",string.valueof(totalsize)); byte[] buffer = new byte[1024]; int bufferlength = 0; while ( (bufferlength = inputstream.read(buffer)) > 0 ) { fileoutput.write(buffer, 0, bufferlength); downloadedsize += bufferlength; } //close output stream when complete // fileoutput.close(); } catch (final ioexception e) { e.printstacktrace(); } log.i("download info","download complete"); try { thread.sleep(2000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } string source = environment.getexternalstoragedirectory() + "/" + filename; log.i("download destination",source); string destination =environment.getexternalstoragedirectory()+ "/"; log.i("extract destination",destination); try { zipfile zipfile = new zipfile(source); zipfile.extractall(destination); } catch (zipexception e) { e.printstacktrace(); } try { httpclient client1 = new defaulthttpclient(); log.i("url is",url1); httppost post1 = new httppost(url1); list<namevaluepair> parameters1 = new arraylist<namevaluepair>(); parameters1.add(new basicnamevaluepair("reqtype", "completeupdate")); parameters1.add(new basicnamevaluepair("menuboxid",mainactivity.abc)); parameters1.add(new basicnamevaluepair("updatetoken", "dmb20101512")); urlencodedformentity ent1 = new urlencodedformentity(parameters1,http.utf_8); post1.setentity(ent1); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } return foo; } @override protected void onpostexecute(string result) { // todo auto-generated method stu super.onpostexecute(result); //result=bn; /*if(!result.isempty()) { calendar c = calendar.getinstance(); int seconds = c.get(calendar.second); log.i("asynctask finish time",string.valueof(seconds)); }*/
}
i using asynctask class in activity task , checking via getstatus method has finished or not ,but never finished above code of asynctask class , postexecute not working can expalin me why?
i have experienced same problem. happens when main ui thread goes sleep. try use timer in ui thread keep awake.
Comments
Post a Comment