Help with pop() and ionViewDidLoad/ionViewDidLeave

OK so I’m working on a language learning app with tables and local audio files that play when you tap certain boxes, and I’ve been struggling to get everything to work with native-audio.

I am preloading the files into memory on the ionViewDidLoad firing and I unload the files from memory on the ionViewDidLeave firing.

The problem is that if I push another page on the nav stack and then pop() back to a previous page, the ionViewDidLoad doesn’t fire a second time so tapping on the chart doesn’t play any audio files. I see the unload logged in console when I push a new page, but they aren’t re-loaded if the page is popped into view.

Can someone help me understand how the nav controller works with respect to viewdidload/viewdidleave and pushing and popping. Popping doesn’t lead to viewdidload firing again, is that correct? Any recommendation on how to re-load audio when a page is popped into view?

try using ionViewDidEnter instead

here when you scroll down page life cycle is described

be sure to use native-audio after platform.ready()

ionViewDidLoad Runs when the page has loaded. This event only happens once per page being created. If a page leaves but is cached, then this event will not fire again on a subsequent viewing. The ionViewDidLoad event is good place to put your setup code for the page.


ionViewDidEnter Runs when the page has fully entered and is now the active page. This event will fire, whether it was the first load or a cached page.

1 Like

More or less:
load = initialization
enter = NavController puts this page on top of stack
leave = NavController no longer has this page on top of stack

There is also a ViewController, which handles modals and other things. The NavController can remain the same while the ViewController changes. So enter and leave does not directly map to what the user sees the app view do.

1 Like

Perfect - thank you for breaking this down and explaining the difference between loading and entering. I must have glossed over that when looking at the docs.

I’ve never messed with the platform.ready() event and my audio is working fine so far. I have a platform included in my constructor on the app.component.ts file and a platform.ready() handler before I modify the statusBar.

Should I be including the platform in the constructor on every page and having the platform.ready() firing lead to audio loading? Doesn’t ionViewDidEnter firing mean that the platform is ready?

Thanks again for the help! A simple find and replace has fixed this issue for me!

No no :smiley: platform.ready() needs to be fired once on app startup. That’s perfectly fine.

1 Like

Ok, great! My audio isn’t on the root page so platform is ready by the time to user gets to a page with audio.

Thanks again for the help!