Mobile apps: How to use OnDestroy to avoid Invalid call of the * error?

Mobile apps: How to use OnDestroy to avoid Invalid call of the * error?

  

Hello everybody, any idea how to correctly use the OnDestroy to avoid these kind of problems?


"Invalid call of the 'BottomBarNewNotificationReceived' client action of the 'MainFlow.Notifications' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action."


I do not use a platform's client action being used as an event handler nor a setTimeout function. I have this from time to time, no idea how to consistently reproduce.


I see there are lots of similar posts, but no clear solution:


https://www.outsystems.com/forums/discussion/27184/how-to-remove-an-event-handler-in-ondestroy-action/

https://www.outsystems.com/forums/discussion/33965/invalid-call-of-the-login-client-action/

https://www.outsystems.com/forums/discussion/30186/invalid-call-of-the-client-action-of-the-since-the-latter-is-not-current/

https://www.outsystems.com/forums/discussion/26797/invalid-call-of-triggerexit-client-action/

https://www.outsystems.com/forums/discussion/21187/invalid-call-of-the-onnotificationreceived-client-action/

https://www.outsystems.com/forums/discussion/32696/error-message/

https://www.outsystems.com/forums/discussion/28519/removing-pushwoosh-notificationreceived-event-listener-ondestroy/

https://www.outsystems.com/forums/discussion/27212/mobile-app-login-invalid-call-of-the-login-client-action-of-the-common-login/

https://www.outsystems.com/forums/discussion/26536/invalid-call-of-the-checkandchangeanchors-client-action/

https://www.outsystems.com/forums/discussion/21671/mobile-app-error-invalid-call-of-the-triggeronupgradeprogress/

https://success.outsystems.com/Documentation/10/Developing_an_Application/Implement_Application_Logic/Screen_and_Block_Lifecycle_Events#On_Navigating_Between_Screens


Thanks for your input!


Kind regards,


Adrian


Hi Adrian,

Is BottomBarNewNotificationReceived an action from a plugin you're using or something that you control?

Yes, I do. But I had these kind of messages in other screens; I begin to think that you can potentially have this on any screen where you use a listener (either on an event or OnAfterFetch listeners) and is caused by some time sensitive issue...


You have to use the OnDestroy event of the BottomBar block to remove the NotificationCounter... action from its subscription source.

You probably have a javascript node where where you're attaching that action to an event, right?

João Neves wrote:

You have to use the OnDestroy event of the BottomBar block to remove the NotificationCounter... action from its subscription source.

You probably have a javascript node where where you're attaching that action to an event, right?

"You probably have a javascript node where where you're attaching that action to an event" - no, I do not use javascript; I only set the listener to the event (see screenshot above). Same thing when you have a screen with an aggregate or Data Action and set the OnAfterFetch listener (local method) on it- how do you remove it? 


Can you share the oml or at least that block?

João Neves wrote:

Can you share the oml or at least that block?

Here it is, only the core module; it won't compile but you will get the idea... Thanks for your help!


Solution


The SyncLocalAlerts action is an asynchronous that can take long time to complete (since it goes to the server). While the function is executing, the user might navigate away to another screen. When the action finishes it will trigger the Notifications Update event which will be handled by an handler of a screen/block that was already destroyed, hence the error.


You should prevent that error, checking a control variable (eg: IsDestroyed) which should be set when the block is destroyed. If the block is destroyed, you skip the event trigger.


Solution

Yes, makes sense; thanks!