java - AsyncTask dont show me message from server (HttpUrlConnection) -


so i'm trying read message server httpurlconnection in asynctask class. problem is, when send request read data server, keeps displaying progresssdialog, doesn't read data server:

public class mainactivity extends activity{  edittext name, password; button login;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     name = (edittext) findviewbyid(r.id.name);     password = (edittext) findviewbyid(r.id.password);     login = (button) findviewbyid(r.id.login);       login.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {              string serverurl = "http://192.168.1.1/my/text.php";             longoperation longoperation = new longoperation();             longoperation.execute(serverurl);           }     });    }  private class longoperation  extends asynctask<string, void, void> {        private string content;     private string error = null;     private progressdialog dialog = new progressdialog(mainactivity.this);      textview uiupdate = (textview) findviewbyid(r.id.output);      @override     protected void onpreexecute() {         uiupdate.settext("output : ");         dialog.setmessage("downloading source..");         dialog.show();     }      @override     protected void doinbackground(string... urls) {         try {             url url = new url(urls[0]);             httpurlconnection client = (httpurlconnection)url.openconnection();             client.connect();             inputstream inputstream = client.getinputstream();             bufferedreader bufferedreader = new bufferedreader(new inputstreamreader(inputstream));             content = bufferedreader.readline();              bufferedreader.close();             inputstream.close();             client.disconnect();          } catch (ioexception e) {             error = e.getmessage();         }          return null;     }     @override     protected void onpostexecute(void unused) {         dialog.dismiss();          if (error != null) {              uiupdate.settext("output : "+error);          } else {              uiupdate.settext("output : "+content);          }     } 

i tryed before connectivity server via httpclient, thats not problem.thanks!

try debugging , see if onpostexecute() method getting called or not.!

this seems stuck in stream reader code. also, add connection timeout of, say, 5-10 seconds better user experience.!

moreover, there seems issue return type of doinbackground() method , input parameter type of onpostexecute() method. per asynctask definition, both should string, isnt it?


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -