Skip to main content

How To Add Double Back Tap Exit For Ionic Apps

In apps these day you don’t see a “are you sure you want to exit” confirm message which gives you ok and cancel as two options but what we see is double back tap exit which when we press the back button gives a toast saying “press again to exit” .

One of the reason for this is the size of phones have increased so it will be much easier to exit an app by double tapping the back button rather than tapping the ok which appears at the center of the screen, and also it looks cool.

So how do we go about coding it for ionic apps? It’s pretty easy as I showed you guys in my previous post how to add back to home button I will be using that code and building form that app so if not already you guys should check that out first.

First we need to install the toast plugin

We add that in the CLI by

 

Now I will change the code form my previous post which asks “Do you want to exit” to the following.

First we need to declare a variable inside the backcallfun() function

 

 

Notice that I am using the $timeout service which will have to be injected into the controller

Watch Video Tutorial Of This Post Here:

 

Leave Me Your Questions And Feedback

Getting your feedback inspires me the most so hit me up in the comments here or on the comments section on my YouTube Channel or on twitter @pointDeveloper
Consider Subscribing / Donating
Subscribe To Mailing List
Donate
If my site was helpful to you, then please consider donating via paypal:

Prantik Vaghela (pointdeveloper)

Hi my name is Prantik Vaghela. I have done my Bachelors and Masters in Computer Science and am a web developer and now a Tutor through my blog. :-)