'Skip a page on back button press if network is available android studio

I'm new to Android, working on a webview app. I have created a custom HTML error page in asset folder for loading when internet not available, it is working fine.

My issue is when internet is back, after browsing different screen on back button press it shows the error page also, how to skip this.

@Override
public void onBackPressed() {
    if (myWebView.canGoBack()) {
        myWebView.goBack();
    } else {
        DashActivity.super.onBackPressed();
    }
}


Solution 1:[1]

In the no internet activity, when you open another activity on getting the internet connection back, you are forgetting to finish() the activity. Due to that, the activity opens again.

Solution 2:[2]

There can be error because you didn't finish the activity so.

You should just write finish() instead of DashActivity.super.onBackPressed()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sambhav. K
Solution 2