FE/IONIC

[ IONIC ] Android backButton control

HEON.D 2021. 4. 5. 10:00
  private appExitConfig() {
    this.platform.backButton.subscribe(async () => {
        if (this.backButtonClickCount === 0) {
            this.navController.back();
            this.backButtonClickCount++;

            const toast = await this.toastCtrl.create({
                message: '뒤로가기 버튼을 한번 더 누르시면 앱이 종료됩니다.',
                duration: 1000
            });
            toast.present();

            setTimeout(() => {
                this.backButtonClickCount = 0;
            }, 1000);
        } else {
            navigator['app'].exitApp();
        }
    });
  }