Question

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 :)

Was it helpful?

Solution

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();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top