HI All,
This question is regarding how to close the application once the user clicks on the **Hardware Back Button** of the device
from the root pages of the application. Currently I am using the following method for back button action.
this.platform.backButton.subscribe(async () => {
}
I am facing the issue when the user reaches the root page and pres the back-button again. The application should close. But it didnt. The code that I am using is
this.routerOutlets.forEach((outlet: IonRouterOutlet) => {
if (outlet && outlet.canGoBack()) {
outlet.pop();
} else if (this.router.url === '/home') {
if (new Date().getTime() - this.lastTimeBackPress < this.timePeriodToExit) {
// this.platform.exitApp(); // Exit from app
navigator['app'].exitApp(); // work in ionic 4
} else {
this.toast.show(
`Press back again to exit App.`,
'2000',
'center')
.subscribe(toast => {
// console.log(JSON.stringify(toast));
});
this.lastTimeBackPress = new Date().getTime();
}
}
});
is there any mistake in my code?
Thanks and Regards
Anand Raj