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!

João Neves wrote:


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.



Hi Joao, please, can you be more specific with an example using this variable IsDestroyed?

Hi Jorge,

1) Create a local variable IsDestroyed in the block

2) Use the OnDestroy event handler of the block to set the IsDestroyed = true

3) Place an If after the call to SyncLocalAlerts to check if the IsDestroyed = true ... and if yes ... go to End - because the block has already been destroyed.

Hi Joao, thank you for your answer. But what happens if i called an OnAfterFetch event and then the screen is destroyed, how can i stop that onAfterFecth before going to the other screen?

Jorge Trujillo wrote:

Hi Joao, thank you for your answer. But what happens if i called an OnAfterFetch event and then the screen is destroyed, how can i stop that onAfterFecth before going to the other screen?

OnAfterFetch won't be called if you navigate away

Actually is being called. Take a look of the following error when I had navigated from the screen with the OnAfterFetch to a new one:

 Invalid call of the 'GetLocalTeamMembersLotsByUserIdOnAfterFetch' client action of the 'ScreenDesignImplementation.LotTasksList' 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.

Are you sure that is is not being called in other places other than the Aggregate OnAfterFetch?

Yes, Im sure.

Which Platform Server version are you running?

Platform Server 10.0.900.0

The OnAfterFetch is actually called, depending on the Platform version. I reported this bug to Support in June this year, and they verified it's a bug, and the fix would be coming end of July. So it should be fixed in the most recent Platform versions, though I haven't checked the release notes. Given that 10.0.900.0 is the latest version, apparently it's not.

The issue was fixed on 10.0.900.0:

RPD-3216 - https://success.outsystems.com/Support/Release_Notes/10/Platform_Server/Platform_Server_10.0.900.0

You have to republish your applications in order to have the issue fixed.


Cool, thanks for the info.

João Neves wrote:

The issue was fixed on 10.0.900.0:

RPD-3216 - https://success.outsystems.com/Support/Release_Notes/10/Platform_Server/Platform_Server_10.0.900.0

You have to republish your applications in order to have the issue fixed.



Hi Joao, I did it, and still I'm getting the same error.

Hi Jorge, can you share an example of the problem happening?


Like João Neves said the issue you are having should be fixed in version 10.0.900.0.


Also, consider reporting this to OutSystems support.

Diogo Paulo wrote:

Hi Jorge, can you share an example of the problem happening?


Like João Neves said the issue you are having should be fixed in version 10.0.900.0.


Also, consider reporting this to OutSystems support.

Hi Diogo, I already reported the issue to OutSystems, they are still working on that. thanks


Hello,

Is there an update on this matter? I face the same issue. 

I also applied the control variable like suggested by João Neves, but it the error is still triggered.


Thank you


Maria João Portela wrote:

Hello,

Is there an update on this matter? I face the same issue. 

I also applied the control variable like suggested by João Neves, but it the error is still triggered.


Thank you

Hi, Maria.

Can you please share an example eSpace/block where this issue is reproducible? Please also confirm you are using OutSystems Platform version 10.0.900.0 or above.

Thank you.


Hello Rui,

I can confirm that the version is superior (10.0.907.0) but I can't share the espace.

I can share screenshots:

This is where the errors are popping up. The two OnAfterFetch keep throwing this error:

Invalid call of the 'GetLocalUserAndLocalSettingsOnAfterFetch' client action of the 'HomeScreen.HomeScreen' 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.

Invalid call of the 'GetLocalAppIntegrationActiveLinksOnAfterFetch' client action of the 'HomeScreen.HomeScreen' 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.

Do you see anything wrong here?

Thank you




Hello!

Any news on this matter?


Thank you!

Adrian wrote:

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


Hii Adrian,


Override the onDestroy() method and in this method Just call finish() and Runtime.getRuntime().gc() methods...

All variables must be assigned NULL...

You can refer code given below: 

@Override
public void onDestroy() {
    super.onDestroy();
    try{
        Runtime.getRuntime().gc();
        finish();
    }catch (Exception e){
        e.printStackTrace();
    }
}






Sagar Rathod wrote:

Adrian wrote:

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


Hii Adrian,


Override the onDestroy() method and in this method Just call finish() and Runtime.getRuntime().gc() methods...

All variables must be assigned NULL...

You can refer code given below: 

@Override
public void onDestroy() {
    super.onDestroy();
    try{
        Runtime.getRuntime().gc();
        finish();
    }catch (Exception e){
        e.printStackTrace();
    }
}







Hi Sagar,


Thanks for your answer, unfortunately I can't test this immediately as my mobile app is gathering dust for the moment while I'm working on different projects. But maybe someone else in the community can validate this?

To be honest I would expect the platform to handle this, we should not need to add any javascript as workaround for these ugly errors.


Kind regards,

Adrian

Hello,

https://www.outsystems.com/forums/discussion/34920/mobile-apps-how-to-use-ondestroy-to-avoid-invalid-call-of-the-error/#Post145442

What I am wondering is, if OutSystems is actively working on this issue.

We have many of these errors every day and it is not nice to see this.

I would rather not do a workaround, but see an actual fix from OutSystems. 

Please let us know what is the status.

Thank you

Hello, Maria.

I'm sorry you are still being affecting by this issue.

We have received reports about these issues in the past and there were two fixes produced for them. In Platform Server 10.0.408.0 a fix for OnAfterFetch of Data Actions was included (RPD-1580). Unfortunately, at that time we had no indication that Screen Aggregates were also being affected by the same issue. When that was found, another fix was produced and released in Platform Server 10.0.900.0, this time for Screen Aggregates as well (RPD- 3216). Currently, we have no open issues related with the error you are facing

I saw that your answered 10.0.907.0 when I asked about the OutSystems Platform Server version being used, but notice that version is actually a Development Environment version. In order to check your Platform Server version you should access your Service Center and look at the right hand side:

There are only three versions of OutSystems 10 Platform Server with the fix: 10.0.900.0, 10.0.904.0 and 10.0.912.0. With that said, can you please confirm which Platform Server version is being used in your environment so we can understand if both fixes are already in place?

If both fixes are actually being used, we are very interested in knowing which pattern is causing the error so we can follow up on that. Ideally, you would be able to provide a reproducing example eSpace (no need to share your actual eSpace) or at least, a sequence of steps that allows us to reproduce it in-house. You can share that through private message or ultimately, you can also open a support case and share that information, if that is more suitable.

The same request applies to Jorge Trujillo.

Thank you.

Hello Rui,

Indeed I posted the wrong version, we do only have Version 10.0.828.0 so you might just be correct on this.

We' ll update the version and then will let you know if these errors stop.

Thank you!


Hi Joao/Kilian

I have used same code in my mobile application in OS version 11. Now I am not getting any error but the issue with me is that I need to pass few values to my parent with the help of event, now what I need to do to resolve this issue.

Please can any one help here.

Thanks,

Rajat Agrawal