Back button subscription does not work

import { Component, OnInit } from '@angular/core';
import { Platform } from '@ionic/angular';

@Component({
    selector: 'app-root',
    templateUrl: 'app.component.html',
    styleUrls: ['app.component.scss']
})
export class AppComponent implements OnInit {

    constructor(private platform: Platform) { }

    ngOnInit(): void {

        this.platform.backButton.subscribeWithPriority(1000, processNextHandler => {
            alert("testing");
            processNextHandler();
        });

    }

}

Using version 5.5.2 of @ionic/angular btw.

Whenever I launch my app via an AVD, I don’t seem to be getting this alert when I press the back button.

Any help would be greatly appreciated, ty!

are you using Cordova or Capacitor?

I’m using Capacitor.

Are you in Capacitor 2 or 3?
In case you are in Capacitor 3, do you have @capacitor/app plugin installed?

I’m using Capacitor 3 and yes, I have the @capacitor/app package installed.


  ionViewDidEnter() {

    this.backButtonSub = this.platform.backButton.subscribeWithPriority(
      10000,
      () => { }
      // do something
    );

  }

try something like this