shmakova shmakova - 1 year ago 113
Android Question

Android WebView - Infinite loop after click

I want to create simple child-safety browser on Android, and I want to check every url before load with this api: But sometimes after click on url starts infinite loop of load this link.
I try to override shouldOverrideUrlLoading like this:

private class BrowserWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;

private interface UrlCheckListener {
void urlChecked(boolean isGood);

private void loadUrl(String query) {
String safeUrl = UrlCheckerUtils.getSafeUrlFromQuery(query);
checkUrlBeforeLoad(safeUrl, valid -> {
if (isViewAttached()) {
if (valid) {
} else {

private void checkUrlBeforeLoad(String url, UrlCheckListener listener) {
try {
URI uri = new URI(url);
String domain = uri.getHost() + "/";

.subscribe(wotResponse -> listener.urlChecked(wotResponse.isSafe()));
} catch (URISyntaxException e) {
Timber.e(e, "Error while parsing url");

loadPageByUrl in view:

public void loadPageByUrl(String url) {

Can you help me to fix this please?

Answer Source

The error was in String safeUrl = UrlCheckerUtils.getSafeUrlFromQuery(query); where I created new object of String. When I start manipulate with url in shouldOverrideUrlLoading, it starts work without infinite redirects.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download