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
cordova plugin add nl.x-services.plugins.toast
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
window.plugins.toast.showShortCenter('Press again to exit');
Notice that I am using the $timeout service which will have to be injected into the controller
Watch Video Tutorial Of This Post Here: