trigger.io

How can I make the Android back button route correctly?


I'm working on a web app packaged by Trigger.io using Android's WebView. In order to keep the normal back button functionality, Trigger provides forge.event.backPressed.preventDefault that:

Prevents the default action when the back button is pressed from the point this is called onwards, allowing the app to handle the event itself using forge.event.backPressed.addListener.

https://trigger.io/docs/current/api/core/event.html#forgeeventbackpressedpreventdefaultcallback-error

The issues:

  1. When the back button's default behavior is not prevented, the back button ends up skipping some navigation history every time it is pressed.
  2. When the default behavior is prevented and I "handle the event [myself] using forge.event.backPressed.addListener", the back button still skips history when pressed.

Solution

  • Thankfully the solution was quite simple. Trigger appears to have some misleading documentation on this.

    Simply call forge.event.backPressed.preventDefault but do not use forge.event.backPressed.addListener. This allows the back button to route the same as it would in the browser.