Android Question

Android Webview loading dialog not being dismissed

I am using the following code

class CustomWebViewClient extends WebViewClient {
Context context;
ProgressDialog pd = null;

public CustomWebViewClient (Context c){
context = c;

public void onPageFinished(WebView view, String url){

public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
pd =, "", "pageload. Please wait...", true);


return true;


When I click a link in the WebView, the dialog appears and the page begins to load, however when the page is finished loading, the dialog is still on the screen. Obviously the code is simple enough, but I cant figure this out. Also, I guess I should add that the links being clicked have a few redirects, but I am not sure if that is related to the cause here.

How can I do this right?

Answer Source

Steven & Sander, try dismissing the progress dialog in a Handler

Something like this:

  class pdHandler extends Handler {
    public void handleMessage(Message msg) {
      if(pd != null)
      pd = null;

Then call your handler in onPageFinished:

 public void onPageFinshed(WebView view, String url){

& you are done!