delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

Progress loading cannot dissmiss #25

Closed jinbatsu closed 8 years ago

jinbatsu commented 8 years ago

This is my snippet code:

public class MainActivity extends AppCompatActivity implements AdvancedWebView.Listener {
    private AdvancedWebView mWebView;
    private ProgressDialog pd;

On Page Started:

    public void onPageStarted(String url, Bitmap favicon) {
        pd = ProgressDialog.show(this, "", "Loading...", true);
    }

On Page Finished:

    public void onPageFinished(String url) {
        if(pd != null && pd.isShowing()) {
           pd.dismiss();
        }
        Toast.makeText(this, "Loaded", Toast.LENGTH_SHORT).show();
    }

The loading is always show, even "Loaded" message has been shown. How to figure out this? Did anyone implement this loading feature?

Thank You

ocram commented 8 years ago

Thanks for your question!

First, please check if your onPageStarted(...), onPageFinished(...) (and possibly also onPageError(...), but this is not required) methods are executed at all. To do so, just insert a Log.d(...) or System.out.println(...) statement in the first line of those methods.

If the correct methods are executed at the right time, the problem in your code is somewhere else -- and not in any way related to this library.

Since you said that the result of Toast.makeText(this, "Loaded", Toast.LENGTH_SHORT).show() is displayed, it seems the problem may indeed be somewhere else in your code.

In that case, please check if pd is null or its method isShowing() returns false in the beginning of onPageFinished(...).

Does that help?

jinbatsu commented 8 years ago

I forget to say that this loading progress is sometimes OK (dismiss), but sometimes it still on progress (not dismiss).

I have a question, what is better for loading indicator to client? Because this "ProgressDialog" make the whole Activity not accessible until it dismissed.

Thank You

ocram commented 8 years ago

The ProgressDialog should be fine. But if you don't like it, you may display a ProgressBar in the layout. Please refer to other sites for these questions, however, as this is not related to this library.

Referring to the problems that we discussed here, please try to debug this as explained before. Maybe onPageError(...) is called so that your dialog is not dismissed.