Issue
I am working on WebView android 4.4 when URL redirect happens loading wheel keep on loading its not dismiss properly. I googled lot but I'm not getting. Can any one explain what is the flow of the WebView android 4.4. Here is my code what I tried :
public class MyWebViewClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
dialog = ProgressDialog.show(getActivity(), null, "Loading...");
dialog.setCancelable(true);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
dialog.dismiss();
}
}
Requesting URL "www.google.com". WebView settings are fine. OnpageFinished not calling after shouldOverrideUrlLoading method.
Solution
I made a mistake in handling progress dialog.
public class MyWebViewClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if(dialog == null){
dialog = ProgressDialog.show(getActivity(), null, "Loading...");
dialog.setCancelable(true);
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if(dialog.isShowing())
dialog.dismiss();
}
}
Now its working fine for all api levels.
Answered By - Aristo Michael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.