Build an app with proper event handling?

Hi everyone !

I am new to Ionic 2 and i am trying to build a simple 3 pages app.

  • The first page has a button to access to the second page
  • When the second page is opened, a 30 seconds countdown begin with a music being played
  • After 30 seconds, a third page (which is actually a modal) is opened. This modal contains a button to reopen the second page.

I want to launch the 30 seconds countdown and the music whenever the user opens the second page and stop it whenever the user leaves the second page.

What the user can do to open the second page :

  • Click on the button from the first page
  • Pause and then resume the app using the device buttons when he is on the second page
  • Click on the device back button when he is on the third page
  • Click on the button from the modal page

Currently i am using

  • Platform.pause to stop the sound and the countdown when the app is paused
  • Platform.resume to restart the sound and the contdown when the app is resumed
  • ionViewDidEnter to start the sound and the countdown
  • ionViewDidLeave to stop the sound and the countdown
  • modal.onDismiss to restart the sound and the countdown
  • I have to register the pause/resume events and unregister them when the users leaves the second page.

It looks really messy and i was wondering if there is a better way to handle the “display/hide second page” events.

Thank you for your help.

Ben