can anyone help with webview

5 months ago by FeelThePower to c/android_dev

For the last few days I have been trying to create "lite" apps for services I use by writing webview applications in android studio using Java. The problem is that when I press the back button on the navigation bar, the apps exit to the launcher instead of returning to the previous webpage. ive tried using

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

even though onBackPressed is deprecated to no avail. ive also tried

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getAction()== KeyEvent.ACTION_DOWN){
            switch (keyCode){
                case KeyEvent.KEYCODE_BACK:
                    if (app.canGoBack()) {

                        app.goBack();
                    }

                    return true;
                    }
            }
        return super.onKeyDown(keyCode, event);
    }

which again fixes nothing. im effectively posting this here as a last resort because nobody else on the entire internet seems to know whats going on and i wanna fix it :( im using the latest version of android studio on windows 11 21h2, writing in java with the latest sdk.

android_dev
android_dev

@programming.dev

login for more options
712
146
8

Welcome to the programming.dev Android development community!

The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License

go to feed...