Skip to content

backbutton fires twice for one Back key press on Android 16 #2028

Closed

Description

@2zovd

Bug Report

Problem

What is expected to happen?

One press of the Back key fires one backbutton event.

What does actually happen?

One press of the Back key fires backbutton twice, about 0.4 ms apart.
A back gesture (edge swipe) fires it once.
Apps that navigate back on backbutton go back two screens for one press.

Information

The same key press reaches CordovaWebViewImpl.onDispatchKeyEvent by two paths (logcat stacks are in the repro repo):

  1. ViewRootImpl$NativePreImeInputStage.doOnBackKeyEvent -> OnBackPressedDispatcher -> the callback from CoreAndroid.overrideBackbutton -> dispatchBackKeyEvent() -> synthetic key -> backbutton.
  2. The real key event continues to ViewRootImpl$ViewPostImeInputStage -> DecorView -> SystemWebView.dispatchKeyEvent -> backbutton.

The synthetic path comes from #1903 and #1910. The code is the same on master.

Command or Code

Repro: https://github.com/2zovd/cordova-backbutton-repro

  1. cordova create, cordova platform add android@15.1.0, no plugins.
  2. Add document.addEventListener("backbutton", ...) that counts events.
  3. Run on Android 16, then run adb shell input keyevent KEYCODE_BACK or press Back in 3-button navigation.

Environment, Platform, Device

Android 16 (API 36) emulator, Pixel 9, Android System WebView 152, gesture navigation enabled.

Version information

cordova CLI 12, cordova-android 15.1.0 (targetSdk 36), no plugins, macOS 26, JDK 21, Gradle 8.14.2.
Not checked on Android 15 and older.

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Activity

  1. GitToTheHub commented on Oct 12, 2026

    @GitToTheHub
    Contributor

    I created a fix in PR #2029.

    You can test it in a fresh Cordova test project by adding the Android platform from the PR branch:

    cordova platform add android@https://github.com/GitToTheHub/cordova-android.git#fix/android-backbutton-once-2028
    cordova run android

    Keep your backbutton counter in the test app and try both a Back key press (adb shell input keyevent KEYCODE_BACK or three-button navigation) and an edge-swipe gesture. Each input should fire exactly one event.

    I verified this on Android 15 and 16 emulators, including rapid consecutive presses. Please let me know whether it also resolves the duplication in your reproduction app.

  2. added a commit that references this issue on Oct 29, 2026
    5394327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions