문제

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