I'm trying to make it so that when the back button on the person's phone is pressed and the focused webview cannot go back, then, super.onBackPressed(); is called and the app minimizes.

public void onBackPressed(){

    if 
    (WV1.isFocused() && WV1.canGoBack()) {
        WV1.goBack();
    }

    else {
        super.onBackPressed();
    }
    if (WV2.isFocused() && WV2.canGoBack()) {
        WV2.goBack();
    }

    else {
        super.onBackPressed();
    }

That's what I'm trying now but it just minimizes the app, if the webview can go back or not.

Thank you for any help in advance :)

有帮助吗?

解决方案

What happens is that you app is performing both actions, making the webview go back AND calling super, which will minimize your app.
That happens because both webviews can't be focused at the same time, therefore either if-else statement will enter the else case, and call super.

This code may solve your problem:

public void onBackPressed() {
    if (WV1.isFocused() && WV1.canGoBack()) {
        WV1.goBack();
    }
    else if (WV2.isFocused() && WV2.canGoBack()) {
        WV2.goBack();
    }
    else {
        super.onBackPressed();
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top