# Disable hardware back button , but exit app on pressed twice

**URL:** <https://forum.ionicframework.com/t/disable-hardware-back-button-but-exit-app-on-pressed-twice/114853>\
**Category:** ionic-v3\
**Created:** [December 9, 2017, 1:27pm UTC](https://forum.ionicframework.com/t/disable-hardware-back-button-but-exit-app-on-pressed-twice/114853 "2017-12-09T13:27:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emiljenson](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/emiljenson/32/109430_2.png) [@emiljenson](https://forum.ionicframework.com/u/emiljenson)\
**Post date:** [December 9, 2017, 1:27pm UTC](https://forum.ionicframework.com/t/disable-hardware-back-button-but-exit-app-on-pressed-twice/114853/1 "2017-12-09T13:27:13Z")

</div>

How to prevent hardware backbutton from redirecting to previous page , but i need to exit app when it is pressed twice.

ie, single press -\> Do nothing  
More than single times -\> Exit app

Somebody help me out

---

<div class="post-metadata">

**Author:** ![emiljenson](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/emiljenson/32/109430_2.png) [@emiljenson](https://forum.ionicframework.com/u/emiljenson)\
**Post date:** [December 9, 2017, 2:18pm UTC](https://forum.ionicframework.com/t/disable-hardware-back-button-but-exit-app-on-pressed-twice/114853/2 "2017-12-09T14:18:59Z")

</div>

somebody ???

---

<div class="post-metadata">

**Author:** ![user5555](https://avatars.discourse-cdn.com/v4/letter/u/8e7dd6/32.png) [@user5555](https://forum.ionicframework.com/u/user5555)\
**Post date:** [December 9, 2017, 3:21pm UTC](https://forum.ionicframework.com/t/disable-hardware-back-button-but-exit-app-on-pressed-twice/114853/3 "2017-12-09T15:21:13Z")

</div>

[https://ionicframework.com/docs/api/platform/Platform/#registerBackButtonAction](https://ionicframework.com/docs/api/platform/Platform/#registerBackButtonAction)

---

<div class="post-metadata">

**Author:** ![emiljenson](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/emiljenson/32/109430_2.png) [@emiljenson](https://forum.ionicframework.com/u/emiljenson)\
**Post date:** [December 9, 2017, 3:53pm UTC](https://forum.ionicframework.com/t/disable-hardware-back-button-but-exit-app-on-pressed-twice/114853/4 "2017-12-09T15:53:25Z")

</div>

Thanks, i was hoping for an example

---

<div class="post-metadata">

**Author:** ![user5555](https://avatars.discourse-cdn.com/v4/letter/u/8e7dd6/32.png) [@user5555](https://forum.ionicframework.com/u/user5555)\
**Post date:** [December 9, 2017, 9:49pm UTC](https://forum.ionicframework.com/t/disable-hardware-back-button-but-exit-app-on-pressed-twice/114853/5 "2017-12-09T21:49:06Z")

</div>

just make a function like this:

```auto
//pseudocode - no gurantee that it will work what so ever
doubletap:boolean = false;
reset (){
 setTimeout(_ =>{this.doubletap = false}, /* milliseconds max between the presses */);
}

backpressed (){
 this.reset();
 if(this.doubletap)
  this.platform.exitApp();
 else
  this.doubletap = true;
}

platform.registerBackButtonAction(backpressed);

```

I also found this gist: [https://gist.github.com/shrekuu/1d0ac923a322f5296a778d3d5c6a9ac9](https://gist.github.com/shrekuu/1d0ac923a322f5296a778d3d5c6a9ac9)

Futhermore look for `ionViewCanLeave` if you want only to restrict going back with the hardware button instead of disabeling it in your app at all.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:59pm UTC](https://forum.ionicframework.com/t/disable-hardware-back-button-but-exit-app-on-pressed-twice/114853/6 "2021-07-19T21:59:46Z")

</div>

Closed on July 19, 2021, 9:59pm UTC


