如果 android webView 中不存在第一个,则加载第二个 URL

Load second URL if first is not present in android webView

我正在为我的本地网络制作一个 webview 应用程序。我有两个静态 IP。我想要做的就是在第一个失败时加载第二个。 (因为其中之一总是 运行)。

我正在做的是在 onRecievedError() 函数中检查它并更改 URL 值,然后像这样再次调用 onCreate()

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
    Toast.makeText(getApplicationContext(), "Failed loading app!", Toast.LENGTH_SHORT).show();
    url1="http://192.168.43.XXX";  //here XXX is used just to hide my IP from public
    onCreate(new Bundle());
}

onCreate() 方法必须呈现新的 URL 但我的应用程序在调用时自行关闭。为什么会这样? 请帮忙,因为我是初学者。

使用此代码

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
    {
        Toast.makeText(getApplicationContext(), "Failed loading app!", Toast.LENGTH_SHORT).show();

        if(failingUrl.equals(url1))
        {
            //you can use load url if fail first url
            // dont't use onCreate again
            webview.loadUrl(url2);
        }
    }