Evan Darwin
Evan Darwin

Reputation: 860

Android ProgressDialog Not Working

This code isn't working. The loading screen doesn't show, however if I take out the http.load() it works fine.

Context ctx = v.getContext();
dialog = ProgressDialog.show(ctx, "Login", "Logging in...");
http.load();

http code:

try
        {
            HttpClient hc = new DefaultHttpClient();
            HttpPost post = newHttpPost("http://www.example.com/");

            HttpResponse rp = hc.execute(post);

            if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            {
                result = EntityUtils.toString(rp.getEntity());
            }
        }catch(IOException e){
            e.printStackTrace();
        }

}

Upvotes: 1

Views: 609

Answers (1)

denis.solonenko
denis.solonenko

Reputation: 11775

That's because you're calling http.load() from UI thread and it gets blocked until this call completes. You should use AsyncTask for that.

Upvotes: 3

Related Questions