# Backbutton event not fired

**URL:** <https://forum.ionicframework.com/t/backbutton-event-not-fired/218753>\
**Category:** Capacitor\
**Created:** [December 25, 2021, 9:03am UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753 "2021-12-25T09:03:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jatton](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@jatton](https://forum.ionicframework.com/u/jatton)\
**Post date:** [December 25, 2021, 9:03am UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/1 "2021-12-25T09:03:58Z")

</div>

Hello,

I am using ionic 5.4.16 and Capacitor.

I have a problem since the beginning with my application on Android :

- When I press the backbutton of my phone, the app is immediately closed
- The events are not trigger. See examples :

```auto
this.platform.ready().then(() => {
      console.log('PLATFORM READY')
      document.addEventListener("backbutton", () => { 
        this.routerOutlets.forEach(async(outlet: IonRouterOutlet) => {
          console.log('BACKBUTTON')
        });
      });
      this.platform.backButton.subscribeWithPriority(0, () => {
          console.log('BACKBUTTON 2')
      });
    });

```

‘PLATFORM READY’ is displayed when the app start but when I press the back button, ‘BACKBUTTON’ is not displayed, the app is closed.

When I press the button, I have theses logs :

```auto
2021-12-25 10:01:22.641 25687-25801/MYAPP I/GED: ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 31, oppidx_max 31, oppidx_min 0
2021-12-25 10:01:22.720 25687-25687/MYAPP W/ContentCatcher: Failed to notify a WebView
2021-12-25 10:01:22.785 25687-25901/MYAPP I/GED: ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 31, oppidx_max 31, oppidx_min 0
2021-12-25 10:01:22.795 25687-25801/MYAPP I/GED: ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 31, oppidx_max 31, oppidx_min 0
2021-12-25 10:01:22.912 25687-25901/com MYAPP Failed to notify a WebView I/GED: ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 31, oppidx_max 31, oppidx_min 0
2021-12-25 10:01:23.003 25687-25687/MYAPP W/Looper: Slow Looper main: doFrame is 314ms late because of 1 msg, msg 1 took 179ms (seq=1233 running=47ms runnable=8ms io=109ms late=108ms h=android.app.ActivityThread$H w=159)

```

Maybe “Failed to notify a WebView” is an idea ?

What am I doing wrong ? is there something specific to do in order to have this event ?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![ciccilleju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ciccilleju/32/135142_2.png) [@ciccilleju](https://forum.ionicframework.com/u/ciccilleju)\
**Post date:** [December 25, 2021, 12:38pm UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/2 "2021-12-25T12:38:31Z")

</div>

Have you added @capacitor/app ?

---

<div class="post-metadata">

**Author:** ![jatton](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@jatton](https://forum.ionicframework.com/u/jatton)\
**Post date:** [December 25, 2021, 7:34pm UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/3 "2021-12-25T19:34:07Z")

</div>

Yes “nom install @capacitor/app” give the result “up to date”

I am running Android studio with the command : “ionic capacitor run android”

In case I have re-done  
`npm install @capacitor/core @capacitor/cli`  
nothing new has been installed.

```auto
npx cap add android
[error] android platform already exists.

```

---

<div class="post-metadata">

**Author:** ![ciccilleju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ciccilleju/32/135142_2.png) [@ciccilleju](https://forum.ionicframework.com/u/ciccilleju)\
**Post date:** [December 25, 2021, 7:46pm UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/4 "2021-12-25T19:46:00Z")

</div>

As soon as i can i will share some code, it allows you to enable the hardware back button

---

<div class="post-metadata">

**Author:** ![ciccilleju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ciccilleju/32/135142_2.png) [@ciccilleju](https://forum.ionicframework.com/u/ciccilleju)\
**Post date:** [December 26, 2021, 9:09am UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/5 "2021-12-26T09:09:56Z")

</div>

```auto
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { Subscription } from 'rxjs';

@Component({
  selector: 'app-mainpage',
  templateUrl: './mainpage.page.html',
  styleUrls: ['./mainpage.page.scss'],
})
export class HomePage {
  backButtonSub: Subscription;
  constructor(
    private platform: Platform,
  ) { }

  ionViewWillEnter() {
    this.backButtonSub = this.platform.backButton.subscribeWithPriority(
      10000,
      () => { }
    );
  }

  ionViewWillLeave() {
    this.backButtonSub.unsubscribe();
  }

}

with this you can enable the hardware backbutton in capacitor apps

```

---

<div class="post-metadata">

**Author:** ![jatton](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@jatton](https://forum.ionicframework.com/u/jatton)\
**Post date:** [December 26, 2021, 10:15am UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/6 "2021-12-26T10:15:36Z")

</div>

> [@ciccilleju](#):
>
> `import { Platform } from '@ionic/angular';`

Thank you ciccilleju,

Your code is not working in my apps but I have created a new fresh apps and it’s working. Something is wrong in my apps, I will continu to investigate and keep you inform.

---

<div class="post-metadata">

**Author:** ![ciccilleju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ciccilleju/32/135142_2.png) [@ciccilleju](https://forum.ionicframework.com/u/ciccilleju)\
**Post date:** [December 26, 2021, 10:53am UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/7 "2021-12-26T10:53:17Z")

</div>

Doesn’t work, how? The button or it gives you some error?  
Let me know 🙂

---

<div class="post-metadata">

**Author:** ![jatton](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@jatton](https://forum.ionicframework.com/u/jatton)\
**Post date:** [December 26, 2021, 4:50pm UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/8 "2021-12-26T16:50:22Z")

</div>

The event was not triggered …

I have solved my problem with this method :

- create a new capacitor app
- copy the new app into the old
- re-set the configuration of my app (install packages, set the app’s name …) it took me 2 hours.

Finally the backbutten is working !

My app was my first ionic’s app, I have made a lot of mistake at the beginning, I think the capacitor configuration was invalid but I can’t tell what was invalid.

---

<div class="post-metadata">

**Author:** ![ciccilleju](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ciccilleju/32/135142_2.png) [@ciccilleju](https://forum.ionicframework.com/u/ciccilleju)\
**Post date:** [December 26, 2021, 4:55pm UTC](https://forum.ionicframework.com/t/backbutton-event-not-fired/218753/9 "2021-12-26T16:55:49Z")

</div>

ok, the most important thing is that, at the end, you’ve made it work 🙂

feel free to contact me if you need any further help, i’m not a “pro” but i’ve used ionic / angular a lot in these last 2 years
