android - Progress bar auto hide in debug mode, but not in a simply run -


unexpected issue i'm getting while run android app. call rest api using progress bar asynctask. somehow progress load correctly , hide correctly while i'm in debugging mode. when run app without debugging mode progress load correctly not hide automatically. below code

'mainactivity.java

import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log; import android.widget.textview;  import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.*; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.message.basicnamevaluepair; import org.apache.http.params.basichttpparams; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import android.app.activity; import android.app.progressdialog; import android.os.asynctask; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.toast;  import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.net.httpurlconnection; import java.net.malformedurlexception; import java.net.url; import java.util.arraylist; import java.util.list;   public class mainactivity extends appcompatactivity {     textview tv1;     progressdialog pd;     button btngetdata;     string myjson;      //url json array //    protected static string url = "http://192.168.1.104:856/api/quotes/getquote/en";       jsonarray user = null;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          setcontentview(r.layout.activity_main);         tv1 = (textview) findviewbyid(r.id.textviewquotes);         btngetdata = (button) findviewbyid(r.id.getdata);         btngetdata.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view view) {                 getdata();               //   new jsonparse().execute("http://192.168.1.104:856/api/quotes/getquote/en");                 string url = "http://192.168.1.104:856/api/quotes/getquote/en";             }         });     }      public void getdata() {         log.w("tag", "get call");          jsonparse g = new jsonparse();         g.execute("");         log.w("tag", "async call end");     }      public void showlist() {         string emplist = "";         try {             jsonobject jobj = new jsonobject(myjson);             string s = jobj.getstring("quotetext");             tv1.settext(s);         } catch (exception e) {          }      }      private class jsonparse extends asynctask<string, void, string> {         private progressdialog pdialog;          @override         protected void onpreexecute() {             super.onpreexecute();            /*  pd = new progressdialog(mainactivity.this);             pd.setmessage("please wait");             pd.setcancelable(false);             pd.show();*/               // pd.dismiss();         }          @override         protected string doinbackground(string... params) {             string xeno = params[0];             list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();             namevaluepairs.add(new basicnamevaluepair("quoteid", xeno));             inputstream inputstream = null;             string result = null;             try {                 android.os.debug.waitfordebugger();                 defaulthttpclient httpclient = new defaulthttpclient(new basichttpparams());                   httpget httppost = new httpget("http://192.168.1.104:856/api/quotes/getquote/en");                 //     httppost.setentity(new urlencodedformentity(namevaluepairs));                 httpresponse response = httpclient.execute(httppost);                 httpentity entity = response.getentity();                 inputstream = entity.getcontent();                 bufferedreader reader = new bufferedreader(new inputstreamreader(inputstream, "utf-8"), 8);                 stringbuilder sb = new stringbuilder();                 string line = null;                 while ((line = reader.readline()) != null) {                     sb.append(line + "\n");                 }                 log.i("tag", sb.tostring());                 result = sb.tostring();              } catch (exception e) {                 toast.maketext(getapplicationcontext(), "error", toast.length_long).show();                 return "error remote server";             } {                 try {                     if (inputstream != null) {                         inputstream.close();                     }                 } catch (exception ex) {                  }             }             return result;         }          @override         protected void onpostexecute(string s) {              /*   if (pd.isshowing()) {                     pd.dismiss();  */              myjson = s;             showlist();         }     } }' 

thanks helping :) i'm new bee in android.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -