android - Loading Dialog on HTTP call OptimusHTTP -


im using optimushttp library on android project. im trying show loading if app contacting server. problem why progress dialog not dismiss. here code.

public void connectrest() {     //using data json dummy     string server = "http://jsonplaceholder.typicode.com/posts/1";     optimushttp client = new optimushttp();     client.enabledebugging();     client.setmethod(optimushttp.method_get);       //parameter     arraymap<string, string> params = new arraymap<>();     params.put("email", "abc@abc.com");     params.put("pass", "abc");        //make request     arraylist<httpreq> refhttpreqlist = new arraylist<>();     try {         //mprogressdialog.show(this, "", "loading", true);         // makerequest() returns reference of request made         // can used later call cancelreq() if required         // if no request made makerequest() returns null         httpreq req = client.makerequest(mainactivity.this, server, params, responselistener);         if (req != null)             refhttpreqlist.add(req);         mprogressdialog.show(this, "loading", "wait while loading...");         if (mprogressdialog != null && mprogressdialog.isshowing()) {             mprogressdialog.dismiss();         }        } catch (exception e) {         e.printstacktrace();     }  }  private final optimushttp.responselistener responselistener = new optimushttp.responselistener() {     @override     public  void onsuccess(string msg) {         system.out.println(msg);         //mprogressdialog.dismiss();         toast.maketext(getapplicationcontext(), msg, toast.length_long).show();      }        @override     public void onfailure(string msg) {         system.out.println(msg);     } }; 

i know library (optimushttp) using asnyc when contacting server. there configuration whether im using sync or async on http connection ? if im include method in async code (double async) ?

i know question seem newbie question. takes learn process become pro :) thanks.

@navotera : can show progressdialogue before making request , when request completes , under listener dismiss progress dialogue.

i.e

...  @override  protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); ... ... // initialize progressdialog final progressdialog progressdialog = new progressdialog(this); progressdialog.setmessage("connecting"); ... ... // show progressdialog before making request   progressdialog.show(); // make request req = client.makerequest(mainactivity.this, server_url, params,new optimushttp.responselistener(){     @override public void onsuccess(string msg) {         system.out.println(msg);             // dismiss progressdialog         progressdialog.dismiss();       }        @override public void onfailure(string msg) {         system.out.println(msg);             // dismiss progressdialog         progressdialog.dismiss();       }     });   

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo