Skip to content Skip to sidebar Skip to footer

OnBackPressed Function Not Working Under IMMERSIVE STICKY Mode

I'm using Immersive Mode for an activity with videoView inside. My goal is when touch on screen, the media controller and the system control bar show or disappear together. Everyth

Solution 1:

If you want to exit the activity when the back button is pressed and the media controller is visible then you can intercept the back button with the following code snippet.

   @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        int keyCode = event.getKeyCode();
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
            return true;
        }
        return super.dispatchKeyEvent(event);
    }

Which is the same solution to a similar problem here Back button not working in Media player


Post a Comment for "OnBackPressed Function Not Working Under IMMERSIVE STICKY Mode"