-1

I am developing an app by using Nativescript with Angular. According to our design, there is a dashboard when application is started. Now the thing I want to do is that when user click on back button in android, I want to confirm with user 'Are you sure you want to exit?'. If user click OK, the app will be killed. If user click No, the app will stay on dashboard page. If you are aware of this, please share me how can I accomplish this.

Thanks & Best Regards, Zaw Zaw Naing

Zaw
  • 11
  • 1
  • 2
  • Possible duplicate of [NativeScript handling back button event](https://stackoverflow.com/questions/40603588/nativescript-handling-back-button-event) – Narendra May 09 '19 at 06:23

1 Answers1

0

You can create a service and maintain current page which can be passed if you want to implement something specific to page. Else you can directly implement logic within below service.

@Injectable()
export class BackService {

    private currentPagePara: CurrentPageParameters; //Custom object only if required
    constructor(

        }

    backHandler() {

        if (application.android) {
            application.android.on(application.AndroidApplication.activityBackPressedEvent, (data: application.AndroidActivityBackPressedEventData) => {
                // Implement your logic here

            });
        } else if (application.ios) {
          console.log("app ios")
        }

    }
}

Inject this service in base component and call backhandler

this._backService.backHandler()
Rajan Phatak
  • 524
  • 8
  • 24