My experience with NativeScript (currently using Angular on Android) has left me feeling like I might be overlooking something important.
Whenever I navigate to a new route, I set up Observable Subscriptions to monitor data changes, navigation changes, and service updates. However, NativeScript keeps a stack of loaded routes in memory.
The issue arises when one of my services triggers a change - even if the corresponding route is hidden deep in the back stack, its subscriptions still get executed. This behavior makes me question why these hidden routes remain active, hinting at a potential memory leak.
This leads me to wonder why NativeScript lacks an onResume & onPause logic similar to that in the Android SDK. With such functionality, I could easily start or stop observers as needed.
In an attempt to address this concern, I've tried utilizing the following code:
ngOnInit() {
console.log('onInit');
}
@HostListener('loaded')
onResume() {
console.log('onResume');
}
@HostListener('unloaded')
onPause() {
console.log('onPause');
}
ngOnDestroy() {
console.log('onDestroy');
}
Despite my efforts, I can't shake off the feeling that I may not be the right person to manage this situation, and that it should ideally be handled by NativeScript's internal SDK. Thank you for your input.